Commit dc27457
committed
Fix bugs in floating point optimizations
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_01UKyzYRFQ9Zm7KsDor34VoY1 parent 5197377 commit dc27457
File tree
3 files changed
+24
-4
lines changed- typed-racket-lib/typed-racket
- base-env
- optimizer
- typed-racket-test/optimizer
3 files changed
+24
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1248 | 1248 | | |
1249 | 1249 | | |
1250 | 1250 | | |
1251 | | - | |
| 1251 | + | |
1252 | 1252 | | |
1253 | 1253 | | |
1254 | 1254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
115 | 123 | | |
116 | 124 | | |
117 | 125 | | |
| |||
144 | 152 | | |
145 | 153 | | |
146 | 154 | | |
| 155 | + | |
| 156 | + | |
147 | 157 | | |
148 | | - | |
| 158 | + | |
| 159 | + | |
149 | 160 | | |
150 | 161 | | |
151 | 162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
103 | 112 | | |
104 | 113 | | |
105 | 114 | | |
| |||
0 commit comments