Bug Description
std.abs(0) returns -0 instead of 0. The absolute value of zero should always be positive zero.
Reproduction
Expected Behavior
Actual Behavior
Notably, std.abs(-0) correctly returns 0:
std.abs(-0) // returns 0 (correct)
std.abs(0) // returns -0 (incorrect)
Version
$ jsonnet --version
Jsonnet commandline interpreter (Go implementation) v0.22.0
Analysis
This is likely caused by the implementation using math.Copysign or similar, which copies the sign bit incorrectly. The Go math.Abs function should handle this correctly:
// math.Abs(0) in Go returns 0 (positive zero)
// math.Abs(-0) in Go returns 0 (positive zero)
sjsonnet correctly returns 0 for both std.abs(0) and std.abs(-0).
Bug Description
std.abs(0)returns-0instead of0. The absolute value of zero should always be positive zero.Reproduction
Expected Behavior
0Actual Behavior
-0Notably,
std.abs(-0)correctly returns0:Version
Analysis
This is likely caused by the implementation using
math.Copysignor similar, which copies the sign bit incorrectly. The Gomath.Absfunction should handle this correctly:sjsonnet correctly returns
0for bothstd.abs(0)andstd.abs(-0).