1 // ignore-test
2
3 // Tests saturating float->int casts. See u128-as-f32.rs for the opposite direction.
4 //
5 // Some of these tests come from a similar file in miri,
6 // tests/run-pass/float.rs. Individual test cases are potentially duplicated
7 // with the previously existing tests, but since this runs so quickly anyway,
8 // we're not spending the time to figure out exactly which ones should be
9 // merged.
10
11 extern crate test;
12
13 use self::test::black_box;
14
15 macro_rules! test {
16 ($val:expr, $src_ty:ident -> $dest_ty:ident, $expected:expr) => (
17 // black_box disables constant evaluation to test run-time conversions:
18 assert_eq!(black_box::<$src_ty>($val) as $dest_ty, $expected,
19 "run-time {} -> {}", stringify!($src_ty), stringify!($dest_ty));
20
21 {
22 const X: $src_ty = $val;
23 const Y: $dest_ty = X as $dest_ty;
24 assert_eq!(Y, $expected,
25 "const eval {} -> {}", stringify!($src_ty), stringify!($dest_ty));
26 }
27 );
28
29 ($fval:expr, f* -> $ity:ident, $ival:expr) => (
30 test!($fval, f32 -> $ity, $ival);
31 test!($fval, f64 -> $ity, $ival);
32 )
33 }
34
35 macro_rules! common_fptoi_tests {
36 ($fty:ident -> $($ity:ident)+) => ({ $(
37 test!($fty::NAN, $fty -> $ity, 0);
38 test!($fty::INFINITY, $fty -> $ity, $ity::MAX);
39 test!($fty::NEG_INFINITY, $fty -> $ity, $ity::MIN);
40 // These two tests are not solely float->int tests, in particular the latter relies on
41 // `u128::MAX as f32` not being UB. But that's okay, since this file tests int->float
42 // as well, the test is just slightly misplaced.
43 test!($ity::MIN as $fty, $fty -> $ity, $ity::MIN);
44 test!($ity::MAX as $fty, $fty -> $ity, $ity::MAX);
45 test!(0., $fty -> $ity, 0);
46 test!($fty::MIN_POSITIVE, $fty -> $ity, 0);
47 test!(-0.9, $fty -> $ity, 0);
48 test!(1., $fty -> $ity, 1);
49 test!(42., $fty -> $ity, 42);
50 )+ });
51
52 (f* -> $($ity:ident)+) => ({
53 common_fptoi_tests!(f32 -> $($ity)+);
54 common_fptoi_tests!(f64 -> $($ity)+);
55 })
56 }
57
58 macro_rules! fptoui_tests {
59 ($fty: ident -> $($ity: ident)+) => ({ $(
60 test!(-0., $fty -> $ity, 0);
61 test!(-$fty::MIN_POSITIVE, $fty -> $ity, 0);
62 test!(-0.99999994, $fty -> $ity, 0);
63 test!(-1., $fty -> $ity, 0);
64 test!(-100., $fty -> $ity, 0);
65 test!(#[allow(overflowing_literals)] -1e50, $fty -> $ity, 0);
66 test!(#[allow(overflowing_literals)] -1e130, $fty -> $ity, 0);
67 )+ });
68
69 (f* -> $($ity:ident)+) => ({
70 fptoui_tests!(f32 -> $($ity)+);
71 fptoui_tests!(f64 -> $($ity)+);
72 })
73 }
74
75 use std::fmt::Debug;
76
77 // Helper function to avoid promotion so that this tests "run-time" casts, not CTFE.
78 #[track_caller]
79 #[inline(never)]
assert_eq<T: PartialEq + Debug>(x: T, y: T)80 fn assert_eq<T: PartialEq + Debug>(x: T, y: T) {
81 assert_eq!(x, y);
82 }
83
84 trait FloatToInt<Int>: Copy {
cast(self) -> Int85 fn cast(self) -> Int;
cast_unchecked(self) -> Int86 unsafe fn cast_unchecked(self) -> Int;
87 }
88
89 impl FloatToInt<i8> for f32 {
cast(self) -> i890 fn cast(self) -> i8 {
91 self as _
92 }
cast_unchecked(self) -> i893 unsafe fn cast_unchecked(self) -> i8 {
94 self.to_int_unchecked()
95 }
96 }
97 impl FloatToInt<i32> for f32 {
cast(self) -> i3298 fn cast(self) -> i32 {
99 self as _
100 }
cast_unchecked(self) -> i32101 unsafe fn cast_unchecked(self) -> i32 {
102 self.to_int_unchecked()
103 }
104 }
105 impl FloatToInt<u32> for f32 {
cast(self) -> u32106 fn cast(self) -> u32 {
107 self as _
108 }
cast_unchecked(self) -> u32109 unsafe fn cast_unchecked(self) -> u32 {
110 self.to_int_unchecked()
111 }
112 }
113 impl FloatToInt<i64> for f32 {
cast(self) -> i64114 fn cast(self) -> i64 {
115 self as _
116 }
cast_unchecked(self) -> i64117 unsafe fn cast_unchecked(self) -> i64 {
118 self.to_int_unchecked()
119 }
120 }
121 impl FloatToInt<u64> for f32 {
cast(self) -> u64122 fn cast(self) -> u64 {
123 self as _
124 }
cast_unchecked(self) -> u64125 unsafe fn cast_unchecked(self) -> u64 {
126 self.to_int_unchecked()
127 }
128 }
129
130 impl FloatToInt<i8> for f64 {
cast(self) -> i8131 fn cast(self) -> i8 {
132 self as _
133 }
cast_unchecked(self) -> i8134 unsafe fn cast_unchecked(self) -> i8 {
135 self.to_int_unchecked()
136 }
137 }
138 impl FloatToInt<i32> for f64 {
cast(self) -> i32139 fn cast(self) -> i32 {
140 self as _
141 }
cast_unchecked(self) -> i32142 unsafe fn cast_unchecked(self) -> i32 {
143 self.to_int_unchecked()
144 }
145 }
146 impl FloatToInt<u32> for f64 {
cast(self) -> u32147 fn cast(self) -> u32 {
148 self as _
149 }
cast_unchecked(self) -> u32150 unsafe fn cast_unchecked(self) -> u32 {
151 self.to_int_unchecked()
152 }
153 }
154 impl FloatToInt<i64> for f64 {
cast(self) -> i64155 fn cast(self) -> i64 {
156 self as _
157 }
cast_unchecked(self) -> i64158 unsafe fn cast_unchecked(self) -> i64 {
159 self.to_int_unchecked()
160 }
161 }
162 impl FloatToInt<u64> for f64 {
cast(self) -> u64163 fn cast(self) -> u64 {
164 self as _
165 }
cast_unchecked(self) -> u64166 unsafe fn cast_unchecked(self) -> u64 {
167 self.to_int_unchecked()
168 }
169 }
170 // FIXME emscripten does not support i128
171 #[cfg(not(target_os = "emscripten"))]
172 impl FloatToInt<i128> for f64 {
cast(self) -> i128173 fn cast(self) -> i128 {
174 self as _
175 }
cast_unchecked(self) -> i128176 unsafe fn cast_unchecked(self) -> i128 {
177 self.to_int_unchecked()
178 }
179 }
180 // FIXME emscripten does not support i128
181 #[cfg(not(target_os = "emscripten"))]
182 impl FloatToInt<u128> for f64 {
cast(self) -> u128183 fn cast(self) -> u128 {
184 self as _
185 }
cast_unchecked(self) -> u128186 unsafe fn cast_unchecked(self) -> u128 {
187 self.to_int_unchecked()
188 }
189 }
190
191 /// Test this cast both via `as` and via `to_int_unchecked` (i.e., it must not saturate).
192 #[track_caller]
193 #[inline(never)]
test_both_cast<F, I>(x: F, y: I) where F: FloatToInt<I>, I: PartialEq + Debug,194 fn test_both_cast<F, I>(x: F, y: I)
195 where
196 F: FloatToInt<I>,
197 I: PartialEq + Debug,
198 {
199 assert_eq!(x.cast(), y);
200 assert_eq!(unsafe { x.cast_unchecked() }, y);
201 }
202
casts()203 fn casts() {
204 // f32 -> i8
205 test_both_cast::<f32, i8>(127.99, 127);
206 test_both_cast::<f32, i8>(-128.99, -128);
207
208 // f32 -> i32
209 test_both_cast::<f32, i32>(0.0, 0);
210 test_both_cast::<f32, i32>(-0.0, 0);
211 test_both_cast::<f32, i32>(/*0x1p-149*/ f32::from_bits(0x00000001), 0);
212 test_both_cast::<f32, i32>(/*-0x1p-149*/ f32::from_bits(0x80000001), 0);
213 test_both_cast::<f32, i32>(/*0x1.19999ap+0*/ f32::from_bits(0x3f8ccccd), 1);
214 test_both_cast::<f32, i32>(/*-0x1.19999ap+0*/ f32::from_bits(0xbf8ccccd), -1);
215 test_both_cast::<f32, i32>(1.9, 1);
216 test_both_cast::<f32, i32>(-1.9, -1);
217 test_both_cast::<f32, i32>(5.0, 5);
218 test_both_cast::<f32, i32>(-5.0, -5);
219 test_both_cast::<f32, i32>(2147483520.0, 2147483520);
220 test_both_cast::<f32, i32>(-2147483648.0, -2147483648);
221 // unrepresentable casts
222 assert_eq::<i32>(2147483648.0f32 as i32, i32::MAX);
223 assert_eq::<i32>(-2147483904.0f32 as i32, i32::MIN);
224 assert_eq::<i32>(f32::MAX as i32, i32::MAX);
225 assert_eq::<i32>(f32::MIN as i32, i32::MIN);
226 assert_eq::<i32>(f32::INFINITY as i32, i32::MAX);
227 assert_eq::<i32>(f32::NEG_INFINITY as i32, i32::MIN);
228 assert_eq::<i32>(f32::NAN as i32, 0);
229 assert_eq::<i32>((-f32::NAN) as i32, 0);
230
231 // f32 -> u32
232 test_both_cast::<f32, u32>(0.0, 0);
233 test_both_cast::<f32, u32>(-0.0, 0);
234 test_both_cast::<f32, u32>(-0.9999999, 0);
235 test_both_cast::<f32, u32>(/*0x1p-149*/ f32::from_bits(0x1), 0);
236 test_both_cast::<f32, u32>(/*-0x1p-149*/ f32::from_bits(0x80000001), 0);
237 test_both_cast::<f32, u32>(/*0x1.19999ap+0*/ f32::from_bits(0x3f8ccccd), 1);
238 test_both_cast::<f32, u32>(1.9, 1);
239 test_both_cast::<f32, u32>(5.0, 5);
240 test_both_cast::<f32, u32>(2147483648.0, 0x8000_0000);
241 test_both_cast::<f32, u32>(4294967040.0, 0u32.wrapping_sub(256));
242 test_both_cast::<f32, u32>(/*-0x1.ccccccp-1*/ f32::from_bits(0xbf666666), 0);
243 test_both_cast::<f32, u32>(/*-0x1.fffffep-1*/ f32::from_bits(0xbf7fffff), 0);
244 test_both_cast::<f32, u32>((u32::MAX - 128) as f32, u32::MAX - 255); // rounding loss
245
246 // unrepresentable casts:
247
248 // rounds up and then becomes unrepresentable
249 assert_eq::<u32>((u32::MAX - 127) as f32 as u32, u32::MAX);
250
251 assert_eq::<u32>(4294967296.0f32 as u32, u32::MAX);
252 assert_eq::<u32>(-5.0f32 as u32, 0);
253 assert_eq::<u32>(f32::MAX as u32, u32::MAX);
254 assert_eq::<u32>(f32::MIN as u32, 0);
255 assert_eq::<u32>(f32::INFINITY as u32, u32::MAX);
256 assert_eq::<u32>(f32::NEG_INFINITY as u32, 0);
257 assert_eq::<u32>(f32::NAN as u32, 0);
258 assert_eq::<u32>((-f32::NAN) as u32, 0);
259
260 // f32 -> i64
261 test_both_cast::<f32, i64>(4294967296.0, 4294967296);
262 test_both_cast::<f32, i64>(-4294967296.0, -4294967296);
263 test_both_cast::<f32, i64>(9223371487098961920.0, 9223371487098961920);
264 test_both_cast::<f32, i64>(-9223372036854775808.0, -9223372036854775808);
265
266 // f64 -> i8
267 test_both_cast::<f64, i8>(127.99, 127);
268 test_both_cast::<f64, i8>(-128.99, -128);
269
270 // f64 -> i32
271 test_both_cast::<f64, i32>(0.0, 0);
272 test_both_cast::<f64, i32>(-0.0, 0);
273 test_both_cast::<f64, i32>(/*0x1.199999999999ap+0*/ f64::from_bits(0x3ff199999999999a), 1);
274 test_both_cast::<f64, i32>(
275 /*-0x1.199999999999ap+0*/ f64::from_bits(0xbff199999999999a),
276 -1,
277 );
278 test_both_cast::<f64, i32>(1.9, 1);
279 test_both_cast::<f64, i32>(-1.9, -1);
280 test_both_cast::<f64, i32>(1e8, 100_000_000);
281 test_both_cast::<f64, i32>(2147483647.0, 2147483647);
282 test_both_cast::<f64, i32>(-2147483648.0, -2147483648);
283 // unrepresentable casts
284 assert_eq::<i32>(2147483648.0f64 as i32, i32::MAX);
285 assert_eq::<i32>(-2147483649.0f64 as i32, i32::MIN);
286
287 // f64 -> i64
288 test_both_cast::<f64, i64>(0.0, 0);
289 test_both_cast::<f64, i64>(-0.0, 0);
290 test_both_cast::<f64, i64>(/*0x0.0000000000001p-1022*/ f64::from_bits(0x1), 0);
291 test_both_cast::<f64, i64>(
292 /*-0x0.0000000000001p-1022*/ f64::from_bits(0x8000000000000001),
293 0,
294 );
295 test_both_cast::<f64, i64>(/*0x1.199999999999ap+0*/ f64::from_bits(0x3ff199999999999a), 1);
296 test_both_cast::<f64, i64>(
297 /*-0x1.199999999999ap+0*/ f64::from_bits(0xbff199999999999a),
298 -1,
299 );
300 test_both_cast::<f64, i64>(5.0, 5);
301 test_both_cast::<f64, i64>(5.9, 5);
302 test_both_cast::<f64, i64>(-5.0, -5);
303 test_both_cast::<f64, i64>(-5.9, -5);
304 test_both_cast::<f64, i64>(4294967296.0, 4294967296);
305 test_both_cast::<f64, i64>(-4294967296.0, -4294967296);
306 test_both_cast::<f64, i64>(9223372036854774784.0, 9223372036854774784);
307 test_both_cast::<f64, i64>(-9223372036854775808.0, -9223372036854775808);
308 // unrepresentable casts
309 assert_eq::<i64>(9223372036854775808.0f64 as i64, i64::MAX);
310 assert_eq::<i64>(-9223372036854777856.0f64 as i64, i64::MIN);
311 assert_eq::<i64>(f64::MAX as i64, i64::MAX);
312 assert_eq::<i64>(f64::MIN as i64, i64::MIN);
313 assert_eq::<i64>(f64::INFINITY as i64, i64::MAX);
314 assert_eq::<i64>(f64::NEG_INFINITY as i64, i64::MIN);
315 assert_eq::<i64>(f64::NAN as i64, 0);
316 assert_eq::<i64>((-f64::NAN) as i64, 0);
317
318 // f64 -> u64
319 test_both_cast::<f64, u64>(0.0, 0);
320 test_both_cast::<f64, u64>(-0.0, 0);
321 test_both_cast::<f64, u64>(-0.99999999999, 0);
322 test_both_cast::<f64, u64>(5.0, 5);
323 test_both_cast::<f64, u64>(1e16, 10000000000000000);
324 test_both_cast::<f64, u64>((u64::MAX - 1024) as f64, u64::MAX - 2047); // rounding loss
325 test_both_cast::<f64, u64>(9223372036854775808.0, 9223372036854775808);
326 // unrepresentable casts
327 assert_eq::<u64>(-5.0f64 as u64, 0);
328 // rounds up and then becomes unrepresentable
329 assert_eq::<u64>((u64::MAX - 1023) as f64 as u64, u64::MAX);
330 assert_eq::<u64>(18446744073709551616.0f64 as u64, u64::MAX);
331 assert_eq::<u64>(f64::MAX as u64, u64::MAX);
332 assert_eq::<u64>(f64::MIN as u64, 0);
333 assert_eq::<u64>(f64::INFINITY as u64, u64::MAX);
334 assert_eq::<u64>(f64::NEG_INFINITY as u64, 0);
335 assert_eq::<u64>(f64::NAN as u64, 0);
336 assert_eq::<u64>((-f64::NAN) as u64, 0);
337
338 // FIXME emscripten does not support i128
339 #[cfg(not(target_os = "emscripten"))]
340 {
341 // f64 -> i128
342 assert_eq::<i128>(f64::MAX as i128, i128::MAX);
343 assert_eq::<i128>(f64::MIN as i128, i128::MIN);
344
345 // f64 -> u128
346 assert_eq::<u128>(f64::MAX as u128, u128::MAX);
347 assert_eq::<u128>(f64::MIN as u128, 0);
348 }
349
350 // int -> f32
351 assert_eq::<f32>(127i8 as f32, 127.0);
352 assert_eq::<f32>(2147483647i32 as f32, 2147483648.0);
353 assert_eq::<f32>((-2147483648i32) as f32, -2147483648.0);
354 assert_eq::<f32>(1234567890i32 as f32, /*0x1.26580cp+30*/ f32::from_bits(0x4e932c06));
355 assert_eq::<f32>(16777217i32 as f32, 16777216.0);
356 assert_eq::<f32>((-16777217i32) as f32, -16777216.0);
357 assert_eq::<f32>(16777219i32 as f32, 16777220.0);
358 assert_eq::<f32>((-16777219i32) as f32, -16777220.0);
359 assert_eq::<f32>(
360 0x7fffff4000000001i64 as f32,
361 /*0x1.fffffep+62*/ f32::from_bits(0x5effffff),
362 );
363 assert_eq::<f32>(
364 0x8000004000000001u64 as i64 as f32,
365 /*-0x1.fffffep+62*/ f32::from_bits(0xdeffffff),
366 );
367 assert_eq::<f32>(
368 0x0020000020000001i64 as f32,
369 /*0x1.000002p+53*/ f32::from_bits(0x5a000001),
370 );
371 assert_eq::<f32>(
372 0xffdfffffdfffffffu64 as i64 as f32,
373 /*-0x1.000002p+53*/ f32::from_bits(0xda000001),
374 );
375 // FIXME emscripten does not support i128
376 #[cfg(not(target_os = "emscripten"))]
377 {
378 assert_eq::<f32>(i128::MIN as f32, -170141183460469231731687303715884105728.0f32);
379 assert_eq::<f32>(u128::MAX as f32, f32::INFINITY); // saturation
380 }
381
382 // int -> f64
383 assert_eq::<f64>(127i8 as f64, 127.0);
384 assert_eq::<f64>(i16::MIN as f64, -32768.0f64);
385 assert_eq::<f64>(2147483647i32 as f64, 2147483647.0);
386 assert_eq::<f64>(-2147483648i32 as f64, -2147483648.0);
387 assert_eq::<f64>(987654321i32 as f64, 987654321.0);
388 assert_eq::<f64>(9223372036854775807i64 as f64, 9223372036854775807.0);
389 assert_eq::<f64>(-9223372036854775808i64 as f64, -9223372036854775808.0);
390 assert_eq::<f64>(4669201609102990i64 as f64, 4669201609102990.0); // Feigenbaum (?)
391 assert_eq::<f64>(9007199254740993i64 as f64, 9007199254740992.0);
392 assert_eq::<f64>(-9007199254740993i64 as f64, -9007199254740992.0);
393 assert_eq::<f64>(9007199254740995i64 as f64, 9007199254740996.0);
394 assert_eq::<f64>(-9007199254740995i64 as f64, -9007199254740996.0);
395 // FIXME emscripten does not support i128
396 #[cfg(not(target_os = "emscripten"))]
397 {
398 // even that fits...
399 assert_eq::<f64>(u128::MAX as f64, 340282366920938463463374607431768211455.0f64);
400 }
401
402 // f32 -> f64
403 assert_eq::<u64>((0.0f32 as f64).to_bits(), 0.0f64.to_bits());
404 assert_eq::<u64>(((-0.0f32) as f64).to_bits(), (-0.0f64).to_bits());
405 assert_eq::<f64>(5.0f32 as f64, 5.0f64);
406 assert_eq::<f64>(
407 /*0x1p-149*/ f32::from_bits(0x1) as f64,
408 /*0x1p-149*/ f64::from_bits(0x36a0000000000000),
409 );
410 assert_eq::<f64>(
411 /*-0x1p-149*/ f32::from_bits(0x80000001) as f64,
412 /*-0x1p-149*/ f64::from_bits(0xb6a0000000000000),
413 );
414 assert_eq::<f64>(
415 /*0x1.fffffep+127*/ f32::from_bits(0x7f7fffff) as f64,
416 /*0x1.fffffep+127*/ f64::from_bits(0x47efffffe0000000),
417 );
418 assert_eq::<f64>(
419 /*-0x1.fffffep+127*/ (-f32::from_bits(0x7f7fffff)) as f64,
420 /*-0x1.fffffep+127*/ -f64::from_bits(0x47efffffe0000000),
421 );
422 assert_eq::<f64>(
423 /*0x1p-119*/ f32::from_bits(0x4000000) as f64,
424 /*0x1p-119*/ f64::from_bits(0x3880000000000000),
425 );
426 assert_eq::<f64>(
427 /*0x1.8f867ep+125*/ f32::from_bits(0x7e47c33f) as f64,
428 6.6382536710104395e+37,
429 );
430 assert_eq::<f64>(f32::INFINITY as f64, f64::INFINITY);
431 assert_eq::<f64>(f32::NEG_INFINITY as f64, f64::NEG_INFINITY);
432
433 // f64 -> f32
434 assert_eq::<u32>((0.0f64 as f32).to_bits(), 0.0f32.to_bits());
435 assert_eq::<u32>(((-0.0f64) as f32).to_bits(), (-0.0f32).to_bits());
436 assert_eq::<f32>(5.0f64 as f32, 5.0f32);
437 assert_eq::<f32>(/*0x0.0000000000001p-1022*/ f64::from_bits(0x1) as f32, 0.0);
438 assert_eq::<f32>(/*-0x0.0000000000001p-1022*/ (-f64::from_bits(0x1)) as f32, -0.0);
439 assert_eq::<f32>(
440 /*0x1.fffffe0000000p-127*/ f64::from_bits(0x380fffffe0000000) as f32,
441 /*0x1p-149*/ f32::from_bits(0x800000),
442 );
443 assert_eq::<f32>(
444 /*0x1.4eae4f7024c7p+108*/ f64::from_bits(0x46b4eae4f7024c70) as f32,
445 /*0x1.4eae5p+108*/ f32::from_bits(0x75a75728),
446 );
447 assert_eq::<f32>(f64::MAX as f32, f32::INFINITY);
448 assert_eq::<f32>(f64::MIN as f32, f32::NEG_INFINITY);
449 assert_eq::<f32>(f64::INFINITY as f32, f32::INFINITY);
450 assert_eq::<f32>(f64::NEG_INFINITY as f32, f32::NEG_INFINITY);
451 }
452
run()453 pub fn run() {
454 casts(); // from miri's tests
455
456 common_fptoi_tests!(f* -> i8 i16 i32 i64 u8 u16 u32 u64);
457 fptoui_tests!(f* -> u8 u16 u32 u64);
458 // FIXME emscripten does not support i128
459 #[cfg(not(target_os = "emscripten"))]
460 {
461 common_fptoi_tests!(f* -> i128 u128);
462 fptoui_tests!(f* -> u128);
463 }
464
465 // The following tests cover edge cases for some integer types.
466
467 // # u8
468 test!(254., f* -> u8, 254);
469 test!(256., f* -> u8, 255);
470
471 // # i8
472 test!(-127., f* -> i8, -127);
473 test!(-129., f* -> i8, -128);
474 test!(126., f* -> i8, 126);
475 test!(128., f* -> i8, 127);
476
477 // # i32
478 // -2147483648. is i32::MIN (exactly)
479 test!(-2147483648., f* -> i32, i32::MIN);
480 // 2147483648. is i32::MAX rounded up
481 test!(2147483648., f32 -> i32, 2147483647);
482 // With 24 significand bits, floats with magnitude in [2^30 + 1, 2^31] are rounded to
483 // multiples of 2^7. Therefore, nextDown(round(i32::MAX)) is 2^31 - 128:
484 test!(2147483520., f32 -> i32, 2147483520);
485 // Similarly, nextUp(i32::MIN) is i32::MIN + 2^8 and nextDown(i32::MIN) is i32::MIN - 2^7
486 test!(-2147483904., f* -> i32, i32::MIN);
487 test!(-2147483520., f* -> i32, -2147483520);
488
489 // # u32
490 // round(MAX) and nextUp(round(MAX))
491 test!(4294967040., f* -> u32, 4294967040);
492 test!(4294967296., f* -> u32, 4294967295);
493
494 // # u128
495 #[cfg(not(target_os = "emscripten"))]
496 {
497 // float->int:
498 test!(f32::MAX, f32 -> u128, 0xffffff00000000000000000000000000);
499 // nextDown(f32::MAX) = 2^128 - 2 * 2^104
500 const SECOND_LARGEST_F32: f32 = 340282326356119256160033759537265639424.;
501 test!(SECOND_LARGEST_F32, f32 -> u128, 0xfffffe00000000000000000000000000);
502 }
503 }
504