Skip to content

fix: std.primitiveEquals(-0.0, 0.0) should return true#912

Closed
He-Pin wants to merge 2 commits into
databricks:masterfrom
He-Pin:fix/primitive-equals-negative-zero
Closed

fix: std.primitiveEquals(-0.0, 0.0) should return true#912
He-Pin wants to merge 2 commits into
databricks:masterfrom
He-Pin:fix/primitive-equals-negative-zero

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Motivation

std.primitiveEquals(-0.0, 0.0) was returning false instead of true.

This is incorrect because IEEE 754 defines -0.0 == 0.0 as true.

Modification

Changed TypeModule.scala to use rawDouble == rawDouble for number comparison instead of ev.compare(x, y) == 0 which uses java.lang.Double.compare that treats -0.0 and 0.0 as different.

Result

std.primitiveEquals(-0.0, 0.0) now returns true, matching go-jsonnet and C++ jsonnet behavior.

References

  • go-jsonnet builtins.go:264 uses left.value == right.value
  • C++ Jsonnet vm.cpp:1436 uses args[0].v.d == args[1].v.d

He-Pin added 2 commits June 10, 2026 14:25
Motivation:
visitLookupSuper (super[key]) silently fell back to self when no
superclass existed, while visitSelectSuper (super.name) correctly
reported "Attempt to use `super` when there is no super class".
This inconsistency could mask bugs in Jsonnet programs and diverged
from go-jsonnet and jrsonnet which both error in this case.

Modification:
Replace the silent `sup = self` fallback in visitLookupSuper with
the same error that visitSelectSuper uses. Change `var sup` to
`val sup` since it is no longer reassigned.

Result:
super[key] and super.name now behave identically when there is no
superclass, both reporting the same error. This matches go-jsonnet
and jrsonnet semantics.
Motivation:
std.primitiveEquals(-0.0, 0.0) was returning false instead of true.
This is incorrect because IEEE 754 defines -0.0 == 0.0 as true.

Modification:
Changed TypeModule.scala to use rawDouble == rawDouble for number
comparison instead of ev.compare(x, y) == 0 which uses
java.lang.Double.compare that treats -0.0 and 0.0 as different.

Result:
std.primitiveEquals(-0.0, 0.0) now returns true, matching go-jsonnet
and C++ jsonnet behavior.

References:
- go-jsonnet builtins.go:264 uses left.value == right.value
- C++ Jsonnet vm.cpp:1436 uses args[0].v.d == args[1].v.d
@He-Pin He-Pin closed this Jun 10, 2026
@He-Pin He-Pin deleted the fix/primitive-equals-negative-zero branch June 10, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant