Skip to content

Fix bugs in floating point optimizations.#1381

Draft
samth wants to merge 4 commits intoracket:masterfrom
samth:flot-opt-fix
Draft

Fix bugs in floating point optimizations.#1381
samth wants to merge 4 commits intoracket:masterfrom
samth:flot-opt-fix

Conversation

@samth
Copy link
Copy Markdown
Member

@samth samth commented Jun 25, 2024

Related to #1042

samth added 4 commits June 25, 2024 15:53
For example, (- (expt 10 309) +inf.0) is -inf.0 but
(- (->fl (expt 10 309)) +inf.0) is nan.0.

Related to racket#1042.
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
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.
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