File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
src/uucore/src/lib/features/format Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -585,7 +585,10 @@ fn format_float_hexadecimal(
585585 } ;
586586
587587 // Convert "XXX" to "X.XX": that divides by 16^precision = 2^(4*precision), so add that to the exponent.
588- let digits = frac2. to_str_radix ( 16 ) ;
588+ let mut digits = frac2. to_str_radix ( 16 ) ;
589+ if case == Case :: Uppercase {
590+ digits. make_ascii_uppercase ( ) ;
591+ }
589592 let ( first_digit, remaining_digits) = digits. split_at ( 1 ) ;
590593 let exponent = exp2 + ( 4 * precision) as i64 ;
591594
@@ -914,6 +917,17 @@ mod test {
914917 assert_eq ! ( f( "0" ) , "0x0.p+0" ) ;
915918 assert_eq ! ( f( "0.125" ) , "0x8.p-6" ) ;
916919 assert_eq ! ( f( "256.0" ) , "0x8.p+5" ) ;
920+
921+ let f = |x| {
922+ format_float_hexadecimal (
923+ & BigDecimal :: from_str ( x) . unwrap ( ) ,
924+ 6 ,
925+ Case :: Uppercase ,
926+ ForceDecimal :: No ,
927+ )
928+ } ;
929+ assert_eq ! ( f( "0.00001" ) , "0xA.7C5AC4P-20" ) ;
930+ assert_eq ! ( f( "0.125" ) , "0x8.000000P-6" ) ;
917931 }
918932
919933 #[ test]
You can’t perform that action at this time.
0 commit comments