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