This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
compiler/rustc_mir_build/src/build
tests/ui/numbers-arithmetic Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -1023,7 +1023,13 @@ pub(crate) fn parse_float_into_scalar(
10231023 let num = num. as_str ( ) ;
10241024 match float_ty {
10251025 // FIXME(f16_f128): When available, compare to the library parser as with `f32` and `f64`
1026- ty:: FloatTy :: F16 => num. parse :: < Half > ( ) . ok ( ) . map ( Scalar :: from_f16) ,
1026+ ty:: FloatTy :: F16 => {
1027+ let mut f = num. parse :: < Half > ( ) . ok ( ) ?;
1028+ if neg {
1029+ f = -f;
1030+ }
1031+ Some ( Scalar :: from_f16 ( f) )
1032+ }
10271033 ty:: FloatTy :: F32 => {
10281034 let Ok ( rust_f) = num. parse :: < f32 > ( ) else { return None } ;
10291035 let mut f = num
@@ -1071,7 +1077,13 @@ pub(crate) fn parse_float_into_scalar(
10711077 Some ( Scalar :: from_f64 ( f) )
10721078 }
10731079 // FIXME(f16_f128): When available, compare to the library parser as with `f32` and `f64`
1074- ty:: FloatTy :: F128 => num. parse :: < Quad > ( ) . ok ( ) . map ( Scalar :: from_f128) ,
1080+ ty:: FloatTy :: F128 => {
1081+ let mut f = num. parse :: < Quad > ( ) . ok ( ) ?;
1082+ if neg {
1083+ f = -f;
1084+ }
1085+ Some ( Scalar :: from_f128 ( f) )
1086+ }
10751087 }
10761088}
10771089
Original file line number Diff line number Diff line change 1+ //@ run-pass
2+
3+ #![ feature( f16) ]
4+ #![ feature( f128) ]
5+
6+ fn main ( ) {
7+ assert_eq ! ( 0.0_f16 . to_bits( ) , 0x0000 ) ;
8+ assert_eq ! ( ( -0.0_f16 ) . to_bits( ) , 0x8000 ) ;
9+ assert_eq ! ( 10.0_f16 . to_bits( ) , 0x4900 ) ;
10+ assert_eq ! ( ( -10.0_f16 ) . to_bits( ) , 0xC900 ) ;
11+
12+ assert_eq ! ( 0.0_f128 . to_bits( ) , 0x0000_0000_0000_0000_0000_0000_0000_0000 ) ;
13+ assert_eq ! ( ( -0.0_f128 ) . to_bits( ) , 0x8000_0000_0000_0000_0000_0000_0000_0000 ) ;
14+ assert_eq ! ( 10.0_f128 . to_bits( ) , 0x4002_4000_0000_0000_0000_0000_0000_0000 ) ;
15+ assert_eq ! ( ( -10.0_f128 ) . to_bits( ) , 0xC002_4000_0000_0000_0000_0000_0000_0000 ) ;
16+ }
You can’t perform that action at this time.
0 commit comments