Fix bugs in floating point optimizations.#1381
Draft
samth wants to merge 4 commits intoracket:masterfrom
Draft
Conversation
Related to racket#1042.
For example, (- (expt 10 309) +inf.0) is -inf.0 but (- (->fl (expt 10 309)) +inf.0) is nan.0. Related to racket#1042.
There was a problem hiding this comment.
Resyntax analyzed 2 files in this pull request and found no issues.
samth
pushed a commit
to samth/typed-racket
that referenced
this pull request
Jan 23, 2026
This commit addresses correctness issues in float optimization: 1. Fix type of (/ 0.0): Changed the division type from (-> -NonPosReal -NonPosReal) to (-> -NegReal -NonPosReal) to correctly handle cases like (/ (min 0.0 0)) which returns +inf.0. 2. Avoid optimizing float exprs when conversion can change result: Added safe-to-convert? check to prevent converting large exact numbers to infinity before operations. For example, (- (expt 10 309) +inf.0) should yield -inf.0, but premature conversion to float would give +nan.0. 3. Added tests for these fixes plus a test for make-polar with NaN arguments to ensure complex NaN is preserved. Based on PR racket#1381. Fixes racket#1042. https://claude.ai/code/session_01UKyzYRFQ9Zm7KsDor34VoY
samth
added a commit
to samth/typed-racket
that referenced
this pull request
Jan 29, 2026
1. Fix type of (/ 0.0): Changed from (-> -NonPosReal -NonPosReal) to (-> -NegReal -NonPosReal) to correctly handle (/ (min 0.0 0)). 2. Avoid optimizing float exprs when conversion can change result: Added safe-to-convert? check to prevent converting large exact numbers to infinity before operations. 3. Fix float-complex multiplication crash with exact integer operands: The imaginary part calculation was using unsafe-fl* with exact integers when non-float optimization preserved exact arithmetic. Based on PR racket#1381. Fixes racket#1042.
2 tasks
samth
added a commit
to samth/typed-racket
that referenced
this pull request
Jan 30, 2026
1. Fix type of (/ 0.0): Changed from (-> -NonPosReal -NonPosReal) to (-> -NegReal -NonPosReal) to correctly handle (/ (min 0.0 0)). 2. Avoid optimizing float exprs when conversion can change result: Added safe-to-convert? check to prevent converting large exact numbers to infinity before operations. 3. Fix float-complex multiplication crash with exact integer operands: The imaginary part calculation was using unsafe-fl* with exact integers when non-float optimization preserved exact arithmetic. Based on PR racket#1381. Fixes racket#1042.
samth
added a commit
to samth/typed-racket
that referenced
this pull request
Feb 2, 2026
1. Fix type of (/ 0.0): Changed from (-> -NonPosReal -NonPosReal) to (-> -NegReal -NonPosReal) to correctly handle (/ (min 0.0 0)). 2. Avoid optimizing float exprs when conversion can change result: Added safe-to-convert? check to prevent converting large exact numbers to infinity before operations. 3. Fix float-complex multiplication crash with exact integer operands: The imaginary part calculation was using unsafe-fl* with exact integers when non-float optimization preserved exact arithmetic. Based on PR racket#1381. Fixes racket#1042.
samth
added a commit
to samth/typed-racket
that referenced
this pull request
Feb 2, 2026
1. Fix type of (/ 0.0): Changed from (-> -NonPosReal -NonPosReal) to (-> -NegReal -NonPosReal) to correctly handle (/ (min 0.0 0)). 2. Avoid optimizing float exprs when conversion can change result: Added safe-to-convert? check to prevent converting large exact numbers to infinity before operations. 3. Fix float-complex multiplication crash with exact integer operands: The imaginary part calculation was using unsafe-fl* with exact integers when non-float optimization preserved exact arithmetic. Based on PR racket#1381. Fixes racket#1042.
samth
added a commit
that referenced
this pull request
Feb 3, 2026
1. Fix type of (/ 0.0): Changed from (-> -NonPosReal -NonPosReal) to (-> -NegReal -NonPosReal) to correctly handle (/ (min 0.0 0)). 2. Avoid optimizing float exprs when conversion can change result: Added safe-to-convert? check to prevent converting large exact numbers to infinity before operations. 3. Fix float-complex multiplication crash with exact integer operands: The imaginary part calculation was using unsafe-fl* with exact integers when non-float optimization preserved exact arithmetic. Based on PR #1381. Fixes #1042.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #1042