Skip to content

fix: TomlRenderer large integers render as decimal not scientific notation#956

Merged
stephenamar-db merged 2 commits into
databricks:masterfrom
He-Pin:fix/toml-renderer-scientific-notation
Jun 18, 2026
Merged

fix: TomlRenderer large integers render as decimal not scientific notation#956
stephenamar-db merged 2 commits into
databricks:masterfrom
He-Pin:fix/toml-renderer-scientific-notation

Conversation

@He-Pin

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

Copy link
Copy Markdown
Contributor

Motivation

TomlRenderer.visitFloat64 rendered large integers like 1e20 as "1.0E20" (scientific notation), which is invalid TOML integer format. go-jsonnet renders 1e20 as 100000000000000000000. The Renderer and BaseCharRenderer had BigDecimal fallback logic, but TomlRenderer was missing it.

Modification

  • Added BigDecimal fallback between the Long-range check and Double.toString: when math.round(d).toDouble != d but d % 1 == 0, uses BigDecimal.toBigInt for exact decimal output
  • Added directional tests: large integer (1e20), regular integer (42), and fraction (3.14)

Result

std.manifestToml({a: 1e20}) now renders a = 100000000000000000000 instead of a = 1.0E20, matching go-jsonnet and producing valid TOML output.

References

Expression go-jsonnet v0.22.0 jrsonnet v0.5.0-pre98 sjsonnet (before) sjsonnet (after)
std.manifestToml({a: 1e20}) a = 100000000000000000000 a = 100000000000000000000 a = 1.0E20 a = 100000000000000000000
std.manifestToml({a: 42}) a = 42 a = 42 a = 42 a = 42
std.manifestToml({a: 3.14}) a = 3.14 a = 3.14 a = 3.14 a = 3.14

@He-Pin He-Pin force-pushed the fix/toml-renderer-scientific-notation branch 2 times, most recently from 79c4fc0 to edb04d7 Compare June 17, 2026 19:34
…ific notation

Motivation:
Large integer values like 1e20 were rendered as "1.0E20" (scientific
notation) in TOML output, which is invalid TOML integer format.
go-jsonnet renders these as "100000000000000000000".

Modification:
- Add BigDecimal fallback in visitFloat64 for integers that exceed
  Long range (where math.round(d).toDouble != d but d % 1 == 0)
- Uses BigDecimal.setScale(0).toBigInt to produce exact decimal string
- Add directional tests verifying large integers, regular integers,
  and fractional values render correctly

Result:
std.manifestToml now renders large integer values as proper decimal
strings instead of scientific notation, matching go-jsonnet behavior.

References: docs/semantic-bugs-v2.md Bug 17
@He-Pin He-Pin force-pushed the fix/toml-renderer-scientific-notation branch from edb04d7 to 97fa49e Compare June 17, 2026 23:24
Motivation:
std.contains only accepts arrays, not strings. The test file used
std.contains with string arguments, causing all CI platforms to fail
with "[std.contains] Wrong parameter type: expected Array, got string".

Modification:
Replace std.contains(large, "E") with
std.length(std.findSubstr("E", large)) == 0 for string substring checks.

Result:
toml_renderer_large_integer.jsonnet test now passes on all platforms.
@stephenamar-db stephenamar-db merged commit 56b348c into databricks:master Jun 18, 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