|
4 | 4 | integer F32_MAX = 16777216; |
5 | 5 | // Value we expect if the value was truncated to float32 space. |
6 | 6 | integer F32_TRUNCATED = 16777215; |
| 7 | +integer INT32_MIN = 0x80000000; |
7 | 8 | float DELTA = 5; |
8 | 9 | float g_f; |
9 | 10 |
|
@@ -102,7 +103,23 @@ default |
102 | 103 | checkTruth("integer->float cast", (integer)((float)(F32_MAX + 5) - 5) == F32_MAX); |
103 | 104 |
|
104 | 105 | // This is _not_ meant to roundtrip correctly. int->float returns a double but float->int takes a float32. |
105 | | - checkTruth("integer->float->integer cast", ((integer)((float)0x7FffFFfe)) == -2147483648); |
| 106 | + checkTruth("integer->float->integer cast", ((integer)((float)0x7FffFFfe)) == INT32_MIN); |
| 107 | + |
| 108 | + // Out-of-range float values should return INT32_MIN (compile-time constant folding) |
| 109 | + checkTruth("float->int overflow positive", ((integer)1e20) == INT32_MIN); |
| 110 | + checkTruth("float->int overflow negative", ((integer)-1e20) == INT32_MIN); |
| 111 | + checkTruth("float->int at boundary", ((integer)2147483648.0) == INT32_MIN); |
| 112 | + checkTruth("float->int just under boundary", ((integer)2147483520.0) == 2147483520); |
| 113 | + |
| 114 | + // Test runtime float->int conversion (not constant-folded) |
| 115 | + float huge = 1e20; |
| 116 | + checkTruth("float->int overflow positive", ((integer)huge) == INT32_MIN); |
| 117 | + huge = -1e20; |
| 118 | + checkTruth("float->int overflow negative", ((integer)huge) == INT32_MIN); |
| 119 | + huge = 2147483648.0; |
| 120 | + checkTruth("float->int at boundary", ((integer)huge) == INT32_MIN); |
| 121 | + huge = 2147483520.0; |
| 122 | + checkTruth("float->int just under boundary", ((integer)huge) == 2147483520); |
106 | 123 |
|
107 | 124 | // This is _also_ not meant to roundtrip correctly. Mono has very janky precision when using the |
108 | 125 | // F<n> format specifier, we need to replicate it. We've ported some of the Mono NumberFormatter |
|
0 commit comments