Skip to content

fix: preserve negative zero in std.round#1044

Merged
stephenamar-db merged 1 commit into
databricks:masterfrom
He-Pin:fix/round-negative-zero-yaml-help
Jun 29, 2026
Merged

fix: preserve negative zero in std.round#1044
stephenamar-db merged 1 commit into
databricks:masterfrom
He-Pin:fix/round-negative-zero-yaml-help

Conversation

@He-Pin

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

Copy link
Copy Markdown
Contributor

Motivation

std.round(-0) returned positive zero in sjsonnet, while go-jsonnet and jrsonnet preserve the negative zero sign. This matters for programs that observe signed zero through functions such as std.atan2.

Modification

  • Preserve the original input when std.round receives either +0 or -0.
  • Keep the existing positive and negative rounding branches for non-zero numbers.
  • Add a regression test that checks the sign of rounded zero values.

Result

Case go-jsonnet v0.22.0 jrsonnet 0.5.0-pre99 sjsonnet before sjsonnet after
std.round(-0) -0 -0 0 -0
std.round(0) 0 0 0 0

std.atan2(std.round(-0), -1) now observes the negative-zero sign.

Risks

  • This intentionally changes materialized output for the exact std.round(-0) case.
  • Other rounding behavior is intended to remain unchanged.

@He-Pin He-Pin marked this pull request as ready for review June 25, 2026 10:59
@He-Pin He-Pin force-pushed the fix/round-negative-zero-yaml-help branch from fe61a64 to 75c6cb9 Compare June 25, 2026 12:47
Comment thread sjsonnet/src/sjsonnet/Val.scala
@He-Pin He-Pin force-pushed the fix/round-negative-zero-yaml-help branch 2 times, most recently from 9d702ba to a146eca Compare June 28, 2026 17:15
@stephenamar-db

Copy link
Copy Markdown
Collaborator

please fix PR.

@He-Pin He-Pin force-pushed the fix/round-negative-zero-yaml-help branch from a146eca to ab773d4 Compare June 28, 2026 21:44
@He-Pin He-Pin force-pushed the fix/round-negative-zero-yaml-help branch from ab773d4 to 3de1b5c Compare June 28, 2026 22:11
@He-Pin He-Pin changed the title fix: error thunk propagation and std.round(-0) sign fix: preserve negative zero in std.round Jun 28, 2026
@He-Pin

He-Pin commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

@stephenamar-db fixed

@stephenamar-db stephenamar-db merged commit 1db39dd into databricks:master Jun 29, 2026
5 checks passed
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.

2 participants