Skip to content

floats: same results on every backend, shortest subnormals, negative zero - #4263

Merged
BaseMax merged 1 commit into
mainfrom
fix-platform-tests
Nov 26, 2026
Merged

BaseMax merged 1 commit into
mainfrom
fix-platform-tests

Conversation

@BaseMax

@BaseMax BaseMax commented Nov 26, 2026 •

Copy link
Copy Markdown
Member
  • The C backend passes -ffp-contract=off unless --fp-contract or --fast-math is given. clang fused a*b+c on arm64, so some results differed in the last digit from LLVM, the interpreter and JS.
  • Subnormal numbers print in their shortest round-trip form (5e-324, not 4.94065645841247e-324), in the native, compiler and JS formatters.
  • Negation keeps the sign of zero in the interpreter and in constant folding (-0.0, 1.0 / -z gives -inf).
  • OOM tests print the signal line on non-Linux hosts, so they pass on macOS.
  • New float_edges test; same output on native, LLVM, interpreter and JS.

Summary by CodeRabbit

  • Bug Fixes

    • Improved floating-point formatting for very small values, including subnormal numbers, while preserving round-trip accuracy.
    • Updated floating-point negation across compilation and interpretation to handle signed zero and edge cases consistently.
    • Compiler builds now explicitly apply floating-point contraction settings based on the selected optimization options.
  • Tests

    • Added coverage for floating-point edge cases and updated expected out-of-memory diagnostics on non-Linux systems.

…zero

The C backend no longer fuses multiply and add unless --fp-contract or --fast-math is given, so it matches LLVM, the interpreter and JS. Subnormals print in their shortest form, and negation keeps the sign of zero in the interpreter and in constant folding. OOM tests print the signal line on non-Linux hosts too.
@BaseMax
BaseMax requested a review from a team as a code owner November 26, 2026 10:25
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes update floating-point negation and formatting across compiler paths, set C compiler contraction flags, and add floating-point edge-case coverage. Non-Linux OOM tests in English and Farsi add an expected SIGABRT diagnostic.

Changes: Floating-point handling

Layer / File(s) Summary
Floating-point unary negation
compiler/codegen/codegen_fmt.salam, compiler/interp/interp_expr.salam, compiler/interp/interp_vmrun.salam, compiler/semantic/sema_consteval.salam, compiler/semantic/sema_fold.salam
These compiler paths now use unary minus to negate floating-point values.
Floating-point formatting precision
std/conv/numfmt/dtoa.salam, compiler/sal_core.salam, compiler/driver/driver.salam, compiler/tests_port/jsgen_run.salam
The affected formatters start at precision 1 for subnormal-magnitude values or values with a zero exponent field. Their existing precision search remains.
Compiler options and floating-point edge cases
compiler/driver/driver_build.salam, tests/en/general/float_edges.salam
C compiler builds select floating-point contraction flags from compiler options. The new test prints values and expressions covering signed zero, small magnitudes, arithmetic, division, and a product-plus-sum expression.

OOM test output

Layer / File(s) Summary
Non-Linux OOM diagnostics
tests/en/general/oom_*.salam, tests/fa/general/oom_*.salam
The non-Linux OOM test output adds an expected fatal SIGABRT diagnostic after the out-of-memory message. Existing exit behavior remains unchanged where described.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: bdadmehr0

Merge Risk: Minimal · up to ffb6c · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names floats, backend consistency, shortest subnormal formatting, and negative zero. The changeset covers all four: the -ffp-contract=off flag in driver_build, the subnormal precision change…
Description check Passed The description follows the template's main parts: it explains the proposed changes and lists what they fix. It covers the fp-contract change, subnormal shortest round-trip printing, negative zero han…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names floats, backend consistency, shortest subnormal formatting, and negative zero. The changeset covers all four: the -ffp-contract=off flag in driver_build, the subnormal precision change in __sal_fmtf, FmtF64, dtoa and the JS prelude, the unary negation changes in interp, vmrun, consteval and fold, and the float_edges test. The title is long and lists several topics, but it still describes the main changes accurately.

Full details: Description check

Explanation

The description follows the template's main parts: it explains the proposed changes and lists what they fix. It covers the fp-contract change, subnormal shortest round-trip printing, negative zero handling, OOM test output on non-Linux hosts, and the new float_edges test. It does not include a related issue, a how-it-was-tested section with commands, or any checklist items, so the template is only partly filled in.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 895c5997-6274-4f3f-b574-017b706135a2
Commits

Reviewing files that changed from the base of the PR and between 60340ae and ffb6c7f.

Files ignored due to path filters: 1

  • tests/en/general/float_edges.out is excluded by !**/*.out
Files selected for processing: 25

  • compiler/codegen/codegen_fmt.salam
  • compiler/driver/driver.salam
  • compiler/driver/driver_build.salam
  • compiler/interp/interp_expr.salam
  • compiler/interp/interp_vmrun.salam
  • compiler/sal_core.salam
  • compiler/semantic/sema_consteval.salam
  • compiler/semantic/sema_fold.salam
  • compiler/tests_port/jsgen_run.salam
  • std/conv/numfmt/dtoa.salam
  • tests/en/general/float_edges.salam
  • tests/en/general/oom_closure_env.salam
  • tests/en/general/oom_dyn_box.salam
  • tests/en/general/oom_hashmap_growth.salam
  • tests/en/general/oom_number_text.salam
  • tests/en/general/oom_string_builder.salam
  • tests/en/general/oom_string_concat.salam
  • tests/en/general/oom_vector_growth.salam
  • tests/fa/general/oom_closure_env.salam
  • tests/fa/general/oom_dyn_box.salam
  • tests/fa/general/oom_hashmap_growth.salam
  • tests/fa/general/oom_number_text.salam
  • tests/fa/general/oom_string_builder.salam
  • tests/fa/general/oom_string_concat.salam
  • tests/fa/general/oom_vector_growth.salam

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@BaseMax
BaseMax merged commit eb6edb4 into main Nov 26, 2026
28 checks passed
@BaseMax
BaseMax deleted the fix-platform-tests branch November 26, 2026 10:47
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