Skip to content

Clamp precision to non-negative for compatibility with Julia 1.14 - #50

Merged
KristofferC merged 1 commit into
JuliaGraphics:masterfrom
KristofferC:kc/negative-precision
Aug 31, 2026
Merged

Clamp precision to non-negative for compatibility with Julia 1.14#50
KristofferC merged 1 commit into
JuliaGraphics:masterfrom
KristofferC:kc/negative-precision

Conversation

@KristofferC

@KristofferC KristofferC commented Aug 27, 2026

Copy link
Copy Markdown
Member

From Julia 1.14, Base.Ryu.writefixed throws ArgumentError("precision must be non-negative") instead of silently truncating on a negative precision.

See for example this PkgEval log: https://pkgeval.s3.us-east-2.amazonaws.com/runs/gh-5428371050/logs/primary/MuladdMacro.log

plain_precision_heuristic returns a negative precision whenever all input values are whole numbers with trailing zeros, so e.g.

showoff([1000.0, 2000.0, 3000.0])

errors on Julia 1.14, which breaks a large number of downstream plotting packages that use Showoff for tick label formatting.

This PR clamps the heuristic result (and, defensively, the precision passed to Ryu.writefixed in format_fixed) to zero. Output is unchanged on older Julia versions for inputs that previously produced a negative precision, since those values have no fractional digits (writefixed(x, -3) and writefixed(x, 0) agree for whole numbers). Adds regression tests and bumps the version to 1.1.1.

plain_precision_heuristic returns a negative precision when all values
are whole numbers with trailing zeros (e.g. [1000.0, 2000.0]). From
Julia 1.14, Base.Ryu.writefixed throws
ArgumentError("precision must be non-negative") instead of silently
truncating, which breaks showoff (and the many plotting packages
depending on it) on such inputs.

Clamp the heuristic result (and the precision passed to writefixed) to
zero. For the inputs that previously produced a negative precision the
output is unchanged, since those values have no fractional digits.
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.65%. Comparing base (e510033) to head (442dcac).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #50   +/-   ##
=======================================
  Coverage   84.65%   84.65%           
=======================================
  Files           2        2           
  Lines         189      189           
=======================================
  Hits          160      160           
  Misses         29       29           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@KristofferC

Copy link
Copy Markdown
Member Author

cc @SimonDanisch

@KristofferC
KristofferC merged commit 0b1034d into JuliaGraphics:master Aug 31, 2026
7 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.

1 participant