@@ -68,7 +68,7 @@ impl FloatToInt<u128> for f64 {
6868/// Test this cast both via `as` and via `approx_unchecked` (i.e., it must not saturate).
6969#[ track_caller]
7070#[ inline( never) ]
71- fn test_cast < F , I > ( x : F , y : I )
71+ fn test_both_cast < F , I > ( x : F , y : I )
7272 where F : FloatToInt < I > , I : PartialEq + Debug
7373{
7474 assert_eq ! ( x. cast( ) , y) ;
@@ -116,22 +116,22 @@ fn basic() {
116116
117117fn casts ( ) {
118118 // f32 -> i8
119- test_cast :: < f32 , i8 > ( 127.99 , 127 ) ;
120- test_cast :: < f32 , i8 > ( -128.99 , -128 ) ;
119+ test_both_cast :: < f32 , i8 > ( 127.99 , 127 ) ;
120+ test_both_cast :: < f32 , i8 > ( -128.99 , -128 ) ;
121121
122122 // f32 -> i32
123- test_cast :: < f32 , i32 > ( 0.0 , 0 ) ;
124- test_cast :: < f32 , i32 > ( -0.0 , 0 ) ;
125- test_cast :: < f32 , i32 > ( /*0x1p-149*/ f32:: from_bits ( 0x00000001 ) , 0 ) ;
126- test_cast :: < f32 , i32 > ( /*-0x1p-149*/ f32:: from_bits ( 0x80000001 ) , 0 ) ;
127- test_cast :: < f32 , i32 > ( /*0x1.19999ap+0*/ f32:: from_bits ( 0x3f8ccccd ) , 1 ) ;
128- test_cast :: < f32 , i32 > ( /*-0x1.19999ap+0*/ f32:: from_bits ( 0xbf8ccccd ) , -1 ) ;
129- test_cast :: < f32 , i32 > ( 1.9 , 1 ) ;
130- test_cast :: < f32 , i32 > ( -1.9 , -1 ) ;
131- test_cast :: < f32 , i32 > ( 5.0 , 5 ) ;
132- test_cast :: < f32 , i32 > ( -5.0 , -5 ) ;
133- test_cast :: < f32 , i32 > ( 2147483520.0 , 2147483520 ) ;
134- test_cast :: < f32 , i32 > ( -2147483648.0 , -2147483648 ) ;
123+ test_both_cast :: < f32 , i32 > ( 0.0 , 0 ) ;
124+ test_both_cast :: < f32 , i32 > ( -0.0 , 0 ) ;
125+ test_both_cast :: < f32 , i32 > ( /*0x1p-149*/ f32:: from_bits ( 0x00000001 ) , 0 ) ;
126+ test_both_cast :: < f32 , i32 > ( /*-0x1p-149*/ f32:: from_bits ( 0x80000001 ) , 0 ) ;
127+ test_both_cast :: < f32 , i32 > ( /*0x1.19999ap+0*/ f32:: from_bits ( 0x3f8ccccd ) , 1 ) ;
128+ test_both_cast :: < f32 , i32 > ( /*-0x1.19999ap+0*/ f32:: from_bits ( 0xbf8ccccd ) , -1 ) ;
129+ test_both_cast :: < f32 , i32 > ( 1.9 , 1 ) ;
130+ test_both_cast :: < f32 , i32 > ( -1.9 , -1 ) ;
131+ test_both_cast :: < f32 , i32 > ( 5.0 , 5 ) ;
132+ test_both_cast :: < f32 , i32 > ( -5.0 , -5 ) ;
133+ test_both_cast :: < f32 , i32 > ( 2147483520.0 , 2147483520 ) ;
134+ test_both_cast :: < f32 , i32 > ( -2147483648.0 , -2147483648 ) ;
135135 // unrepresentable casts
136136 assert_eq :: < i32 > ( 2147483648.0f32 as i32 , i32:: MAX ) ;
137137 assert_eq :: < i32 > ( -2147483904.0f32 as i32 , i32:: MIN ) ;
@@ -143,19 +143,19 @@ fn casts() {
143143 assert_eq :: < i32 > ( ( -f32:: NAN ) as i32 , 0 ) ;
144144
145145 // f32 -> u32
146- test_cast :: < f32 , u32 > ( 0.0 , 0 ) ;
147- test_cast :: < f32 , u32 > ( -0.0 , 0 ) ;
148- test_cast :: < f32 , u32 > ( -0.9999999 , 0 ) ;
149- test_cast :: < f32 , u32 > ( /*0x1p-149*/ f32:: from_bits ( 0x1 ) , 0 ) ;
150- test_cast :: < f32 , u32 > ( /*-0x1p-149*/ f32:: from_bits ( 0x80000001 ) , 0 ) ;
151- test_cast :: < f32 , u32 > ( /*0x1.19999ap+0*/ f32:: from_bits ( 0x3f8ccccd ) , 1 ) ;
152- test_cast :: < f32 , u32 > ( 1.9 , 1 ) ;
153- test_cast :: < f32 , u32 > ( 5.0 , 5 ) ;
154- test_cast :: < f32 , u32 > ( 2147483648.0 , 0x8000_0000 ) ;
155- test_cast :: < f32 , u32 > ( 4294967040.0 , 0u32 . wrapping_sub ( 256 ) ) ;
156- test_cast :: < f32 , u32 > ( /*-0x1.ccccccp-1*/ f32:: from_bits ( 0xbf666666 ) , 0 ) ;
157- test_cast :: < f32 , u32 > ( /*-0x1.fffffep-1*/ f32:: from_bits ( 0xbf7fffff ) , 0 ) ;
158- test_cast :: < f32 , u32 > ( ( u32:: MAX -128 ) as f32 , u32:: MAX -255 ) ; // rounding loss
146+ test_both_cast :: < f32 , u32 > ( 0.0 , 0 ) ;
147+ test_both_cast :: < f32 , u32 > ( -0.0 , 0 ) ;
148+ test_both_cast :: < f32 , u32 > ( -0.9999999 , 0 ) ;
149+ test_both_cast :: < f32 , u32 > ( /*0x1p-149*/ f32:: from_bits ( 0x1 ) , 0 ) ;
150+ test_both_cast :: < f32 , u32 > ( /*-0x1p-149*/ f32:: from_bits ( 0x80000001 ) , 0 ) ;
151+ test_both_cast :: < f32 , u32 > ( /*0x1.19999ap+0*/ f32:: from_bits ( 0x3f8ccccd ) , 1 ) ;
152+ test_both_cast :: < f32 , u32 > ( 1.9 , 1 ) ;
153+ test_both_cast :: < f32 , u32 > ( 5.0 , 5 ) ;
154+ test_both_cast :: < f32 , u32 > ( 2147483648.0 , 0x8000_0000 ) ;
155+ test_both_cast :: < f32 , u32 > ( 4294967040.0 , 0u32 . wrapping_sub ( 256 ) ) ;
156+ test_both_cast :: < f32 , u32 > ( /*-0x1.ccccccp-1*/ f32:: from_bits ( 0xbf666666 ) , 0 ) ;
157+ test_both_cast :: < f32 , u32 > ( /*-0x1.fffffep-1*/ f32:: from_bits ( 0xbf7fffff ) , 0 ) ;
158+ test_both_cast :: < f32 , u32 > ( ( u32:: MAX -128 ) as f32 , u32:: MAX -255 ) ; // rounding loss
159159 // unrepresentable casts
160160 assert_eq :: < u32 > ( ( u32:: MAX -127 ) as f32 as u32 , u32:: MAX ) ; // rounds up and then becomes unrepresentable
161161 assert_eq :: < u32 > ( 4294967296.0f32 as u32 , u32:: MAX ) ;
@@ -168,44 +168,44 @@ fn casts() {
168168 assert_eq :: < u32 > ( ( -f32:: NAN ) as u32 , 0 ) ;
169169
170170 // f32 -> i64
171- test_cast :: < f32 , i64 > ( 4294967296.0 , 4294967296 ) ;
172- test_cast :: < f32 , i64 > ( -4294967296.0 , -4294967296 ) ;
173- test_cast :: < f32 , i64 > ( 9223371487098961920.0 , 9223371487098961920 ) ;
174- test_cast :: < f32 , i64 > ( -9223372036854775808.0 , -9223372036854775808 ) ;
171+ test_both_cast :: < f32 , i64 > ( 4294967296.0 , 4294967296 ) ;
172+ test_both_cast :: < f32 , i64 > ( -4294967296.0 , -4294967296 ) ;
173+ test_both_cast :: < f32 , i64 > ( 9223371487098961920.0 , 9223371487098961920 ) ;
174+ test_both_cast :: < f32 , i64 > ( -9223372036854775808.0 , -9223372036854775808 ) ;
175175
176176 // f64 -> i8
177- test_cast :: < f64 , i8 > ( 127.99 , 127 ) ;
178- test_cast :: < f64 , i8 > ( -128.99 , -128 ) ;
177+ test_both_cast :: < f64 , i8 > ( 127.99 , 127 ) ;
178+ test_both_cast :: < f64 , i8 > ( -128.99 , -128 ) ;
179179
180180 // f64 -> i32
181- test_cast :: < f64 , i32 > ( 0.0 , 0 ) ;
182- test_cast :: < f64 , i32 > ( -0.0 , 0 ) ;
183- test_cast :: < f64 , i32 > ( /*0x1.199999999999ap+0*/ f64:: from_bits ( 0x3ff199999999999a ) , 1 ) ;
184- test_cast :: < f64 , i32 > ( /*-0x1.199999999999ap+0*/ f64:: from_bits ( 0xbff199999999999a ) , -1 ) ;
185- test_cast :: < f64 , i32 > ( 1.9 , 1 ) ;
186- test_cast :: < f64 , i32 > ( -1.9 , -1 ) ;
187- test_cast :: < f64 , i32 > ( 1e8 , 100_000_000 ) ;
188- test_cast :: < f64 , i32 > ( 2147483647.0 , 2147483647 ) ;
189- test_cast :: < f64 , i32 > ( -2147483648.0 , -2147483648 ) ;
181+ test_both_cast :: < f64 , i32 > ( 0.0 , 0 ) ;
182+ test_both_cast :: < f64 , i32 > ( -0.0 , 0 ) ;
183+ test_both_cast :: < f64 , i32 > ( /*0x1.199999999999ap+0*/ f64:: from_bits ( 0x3ff199999999999a ) , 1 ) ;
184+ test_both_cast :: < f64 , i32 > ( /*-0x1.199999999999ap+0*/ f64:: from_bits ( 0xbff199999999999a ) , -1 ) ;
185+ test_both_cast :: < f64 , i32 > ( 1.9 , 1 ) ;
186+ test_both_cast :: < f64 , i32 > ( -1.9 , -1 ) ;
187+ test_both_cast :: < f64 , i32 > ( 1e8 , 100_000_000 ) ;
188+ test_both_cast :: < f64 , i32 > ( 2147483647.0 , 2147483647 ) ;
189+ test_both_cast :: < f64 , i32 > ( -2147483648.0 , -2147483648 ) ;
190190 // unrepresentable casts
191191 assert_eq :: < i32 > ( 2147483648.0f64 as i32 , i32:: MAX ) ;
192192 assert_eq :: < i32 > ( -2147483649.0f64 as i32 , i32:: MIN ) ;
193193
194194 // f64 -> i64
195- test_cast :: < f64 , i64 > ( 0.0 , 0 ) ;
196- test_cast :: < f64 , i64 > ( -0.0 , 0 ) ;
197- test_cast :: < f64 , i64 > ( /*0x0.0000000000001p-1022*/ f64:: from_bits ( 0x1 ) , 0 ) ;
198- test_cast :: < f64 , i64 > ( /*-0x0.0000000000001p-1022*/ f64:: from_bits ( 0x8000000000000001 ) , 0 ) ;
199- test_cast :: < f64 , i64 > ( /*0x1.199999999999ap+0*/ f64:: from_bits ( 0x3ff199999999999a ) , 1 ) ;
200- test_cast :: < f64 , i64 > ( /*-0x1.199999999999ap+0*/ f64:: from_bits ( 0xbff199999999999a ) , -1 ) ;
201- test_cast :: < f64 , i64 > ( 5.0 , 5 ) ;
202- test_cast :: < f64 , i64 > ( 5.9 , 5 ) ;
203- test_cast :: < f64 , i64 > ( -5.0 , -5 ) ;
204- test_cast :: < f64 , i64 > ( -5.9 , -5 ) ;
205- test_cast :: < f64 , i64 > ( 4294967296.0 , 4294967296 ) ;
206- test_cast :: < f64 , i64 > ( -4294967296.0 , -4294967296 ) ;
207- test_cast :: < f64 , i64 > ( 9223372036854774784.0 , 9223372036854774784 ) ;
208- test_cast :: < f64 , i64 > ( -9223372036854775808.0 , -9223372036854775808 ) ;
195+ test_both_cast :: < f64 , i64 > ( 0.0 , 0 ) ;
196+ test_both_cast :: < f64 , i64 > ( -0.0 , 0 ) ;
197+ test_both_cast :: < f64 , i64 > ( /*0x0.0000000000001p-1022*/ f64:: from_bits ( 0x1 ) , 0 ) ;
198+ test_both_cast :: < f64 , i64 > ( /*-0x0.0000000000001p-1022*/ f64:: from_bits ( 0x8000000000000001 ) , 0 ) ;
199+ test_both_cast :: < f64 , i64 > ( /*0x1.199999999999ap+0*/ f64:: from_bits ( 0x3ff199999999999a ) , 1 ) ;
200+ test_both_cast :: < f64 , i64 > ( /*-0x1.199999999999ap+0*/ f64:: from_bits ( 0xbff199999999999a ) , -1 ) ;
201+ test_both_cast :: < f64 , i64 > ( 5.0 , 5 ) ;
202+ test_both_cast :: < f64 , i64 > ( 5.9 , 5 ) ;
203+ test_both_cast :: < f64 , i64 > ( -5.0 , -5 ) ;
204+ test_both_cast :: < f64 , i64 > ( -5.9 , -5 ) ;
205+ test_both_cast :: < f64 , i64 > ( 4294967296.0 , 4294967296 ) ;
206+ test_both_cast :: < f64 , i64 > ( -4294967296.0 , -4294967296 ) ;
207+ test_both_cast :: < f64 , i64 > ( 9223372036854774784.0 , 9223372036854774784 ) ;
208+ test_both_cast :: < f64 , i64 > ( -9223372036854775808.0 , -9223372036854775808 ) ;
209209 // unrepresentable casts
210210 assert_eq :: < i64 > ( 9223372036854775808.0f64 as i64 , i64:: MAX ) ;
211211 assert_eq :: < i64 > ( -9223372036854777856.0f64 as i64 , i64:: MIN ) ;
@@ -217,13 +217,13 @@ fn casts() {
217217 assert_eq :: < i64 > ( ( -f64:: NAN ) as i64 , 0 ) ;
218218
219219 // f64 -> u64
220- test_cast :: < f64 , u64 > ( 0.0 , 0 ) ;
221- test_cast :: < f64 , u64 > ( -0.0 , 0 ) ;
222- test_cast :: < f64 , u64 > ( -0.99999999999 , 0 ) ;
223- test_cast :: < f64 , u64 > ( 5.0 , 5 ) ;
224- test_cast :: < f64 , u64 > ( 1e16 , 10000000000000000 ) ;
225- test_cast :: < f64 , u64 > ( ( u64:: MAX -1024 ) as f64 , u64:: MAX -2047 ) ; // rounding loss
226- test_cast :: < f64 , u64 > ( 9223372036854775808.0 , 9223372036854775808 ) ;
220+ test_both_cast :: < f64 , u64 > ( 0.0 , 0 ) ;
221+ test_both_cast :: < f64 , u64 > ( -0.0 , 0 ) ;
222+ test_both_cast :: < f64 , u64 > ( -0.99999999999 , 0 ) ;
223+ test_both_cast :: < f64 , u64 > ( 5.0 , 5 ) ;
224+ test_both_cast :: < f64 , u64 > ( 1e16 , 10000000000000000 ) ;
225+ test_both_cast :: < f64 , u64 > ( ( u64:: MAX -1024 ) as f64 , u64:: MAX -2047 ) ; // rounding loss
226+ test_both_cast :: < f64 , u64 > ( 9223372036854775808.0 , 9223372036854775808 ) ;
227227 // unrepresentable casts
228228 assert_eq :: < u64 > ( -5.0f64 as u64 , 0 ) ;
229229 assert_eq :: < u64 > ( ( u64:: MAX -1023 ) as f64 as u64 , u64:: MAX ) ; // rounds up and then becomes unrepresentable
0 commit comments