diff --git a/sjsonnet/src/sjsonnet/stdlib/MathModule.scala b/sjsonnet/src/sjsonnet/stdlib/MathModule.scala index 65612cf8..8ec43255 100644 --- a/sjsonnet/src/sjsonnet/stdlib/MathModule.scala +++ b/sjsonnet/src/sjsonnet/stdlib/MathModule.scala @@ -552,7 +552,7 @@ object MathModule extends AbstractFunctionModule { * The official docs list std.mantissa(x) as a mathematical function. */ builtin("mantissa", "x") { (pos, ev, x: Double) => - if (x == 0) 0.0 + if (x == 0) x else { val bits = java.lang.Double.doubleToRawLongBits(x) val absBits = bits & 0x7fffffffffffffffL diff --git a/sjsonnet/test/resources/new_test_suite/mantissa_negative_zero.jsonnet b/sjsonnet/test/resources/new_test_suite/mantissa_negative_zero.jsonnet new file mode 100644 index 00000000..442d2241 --- /dev/null +++ b/sjsonnet/test/resources/new_test_suite/mantissa_negative_zero.jsonnet @@ -0,0 +1,7 @@ +// std.mantissa must preserve the sign of negative zero. +// assertEqual cannot distinguish -0.0 from 0.0 (IEEE equality), +// so we observe the sign through std.toString rendering. +std.toString(std.mantissa(0 * -1)) == "-0" && +std.toString(std.mantissa(0)) == "0" && +std.toString(std.mantissa(1.5)) == "0.75" && +std.toString(std.mantissa(-1.5)) == "-0.75" diff --git a/sjsonnet/test/resources/new_test_suite/mantissa_negative_zero.jsonnet.golden b/sjsonnet/test/resources/new_test_suite/mantissa_negative_zero.jsonnet.golden new file mode 100644 index 00000000..27ba77dd --- /dev/null +++ b/sjsonnet/test/resources/new_test_suite/mantissa_negative_zero.jsonnet.golden @@ -0,0 +1 @@ +true