Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sjsonnet/src/sjsonnet/stdlib/MathModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ object MathModule extends AbstractFunctionModule {
// adding 0.5 would invoke IEEE 754 round-to-even and produce the wrong
// result for odd inputs (e.g. 2^53 - 1). Short-circuit to avoid it.
if (x != x || math.abs(x) >= 4503599627370496.0) x
else if (x >= 0) math.floor(x + 0.5)
else if (x == 0) x
else if (x > 0) math.floor(x + 0.5)
else math.ceil(x - 0.5)
},
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// round(-0) should preserve negative zero sign
roundNegZero: std.round(-0),
// round(0) should stay positive zero
roundPosZero: std.round(0),
// round(-0.4) should produce -0
roundNegSmall: std.round(-0.4),
// round(0.5) should produce 1
roundHalfUp: std.round(0.5),
// round(-0.5) should produce -1
roundNegHalf: std.round(-0.5),
// atan2 verifies sign of zero
signNegZero: std.atan2(std.round(-0), -1) < 0,
signPosZero: std.atan2(std.round(0), -1) > 0,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"roundHalfUp": 1,
"roundNegHalf": -1,
"roundNegSmall": -0,
"roundNegZero": -0,
"roundPosZero": 0,
"signNegZero": true,
"signPosZero": true
}
Loading