@@ -469,11 +469,7 @@ pub enum ScalarValue {
469469
470470impl Hash for Fl < f16 > {
471471 fn hash < H : Hasher > ( & self , state : & mut H ) {
472- let bits = self . 0 . to_bits ( ) ;
473- // +0.0 and -0.0 differ only in the sign bit but compare equal under
474- // IEEE 754; normalize -0.0 → +0.0 so Hash agrees with Eq.
475- let bits = if bits << 1 == 0 { 0 } else { bits } ;
476- bits. hash ( state) ;
472+ self . 0 . to_bits ( ) . hash ( state) ;
477473 }
478474}
479475
@@ -504,26 +500,17 @@ impl PartialEq for ScalarValue {
504500 ( Boolean ( v1) , Boolean ( v2) ) => v1. eq ( v2) ,
505501 ( Boolean ( _) , _) => false ,
506502 ( Float32 ( v1) , Float32 ( v2) ) => match ( v1, v2) {
507- ( Some ( f1) , Some ( f2) ) => {
508- let ( b1, b2) = ( f1. to_bits ( ) , f2. to_bits ( ) ) ;
509- ( ( b1 << 1 ) == 0 && ( b2 << 1 ) == 0 ) || b1 == b2
510- }
503+ ( Some ( f1) , Some ( f2) ) => f1. to_bits ( ) == f2. to_bits ( ) ,
511504 _ => v1. eq ( v2) ,
512505 } ,
513506 ( Float16 ( v1) , Float16 ( v2) ) => match ( v1, v2) {
514- ( Some ( f1) , Some ( f2) ) => {
515- let ( b1, b2) = ( f1. to_bits ( ) , f2. to_bits ( ) ) ;
516- ( ( b1 << 1 ) == 0 && ( b2 << 1 ) == 0 ) || b1 == b2
517- }
507+ ( Some ( f1) , Some ( f2) ) => f1. to_bits ( ) == f2. to_bits ( ) ,
518508 _ => v1. eq ( v2) ,
519509 } ,
520510 ( Float32 ( _) , _) => false ,
521511 ( Float16 ( _) , _) => false ,
522512 ( Float64 ( v1) , Float64 ( v2) ) => match ( v1, v2) {
523- ( Some ( f1) , Some ( f2) ) => {
524- let ( b1, b2) = ( f1. to_bits ( ) , f2. to_bits ( ) ) ;
525- ( ( b1 << 1 ) == 0 && ( b2 << 1 ) == 0 ) || b1 == b2
526- }
513+ ( Some ( f1) , Some ( f2) ) => f1. to_bits ( ) == f2. to_bits ( ) ,
527514 _ => v1. eq ( v2) ,
528515 } ,
529516 ( Float64 ( _) , _) => false ,
@@ -669,35 +656,17 @@ impl PartialOrd for ScalarValue {
669656 ( Boolean ( v1) , Boolean ( v2) ) => v1. partial_cmp ( v2) ,
670657 ( Boolean ( _) , _) => None ,
671658 ( Float32 ( v1) , Float32 ( v2) ) => match ( v1, v2) {
672- ( Some ( a) , Some ( b) ) => {
673- Some ( if a. to_bits ( ) << 1 == 0 && b. to_bits ( ) << 1 == 0 {
674- Ordering :: Equal
675- } else {
676- a. total_cmp ( b)
677- } )
678- }
659+ ( Some ( f1) , Some ( f2) ) => Some ( f1. total_cmp ( f2) ) ,
679660 _ => v1. partial_cmp ( v2) ,
680661 } ,
681662 ( Float16 ( v1) , Float16 ( v2) ) => match ( v1, v2) {
682- ( Some ( a) , Some ( b) ) => {
683- Some ( if a. to_bits ( ) << 1 == 0 && b. to_bits ( ) << 1 == 0 {
684- Ordering :: Equal
685- } else {
686- a. total_cmp ( b)
687- } )
688- }
663+ ( Some ( f1) , Some ( f2) ) => Some ( f1. total_cmp ( f2) ) ,
689664 _ => v1. partial_cmp ( v2) ,
690665 } ,
691666 ( Float32 ( _) , _) => None ,
692667 ( Float16 ( _) , _) => None ,
693668 ( Float64 ( v1) , Float64 ( v2) ) => match ( v1, v2) {
694- ( Some ( a) , Some ( b) ) => {
695- Some ( if a. to_bits ( ) << 1 == 0 && b. to_bits ( ) << 1 == 0 {
696- Ordering :: Equal
697- } else {
698- a. total_cmp ( b)
699- } )
700- }
669+ ( Some ( f1) , Some ( f2) ) => Some ( f1. total_cmp ( f2) ) ,
701670 _ => v1. partial_cmp ( v2) ,
702671 } ,
703672 ( Float64 ( _) , _) => None ,
@@ -972,11 +941,7 @@ macro_rules! hash_float_value {
972941 $( impl std:: hash:: Hash for Fl <$t> {
973942 #[ inline]
974943 fn hash<H : std:: hash:: Hasher >( & self , state: & mut H ) {
975- let bits = <$i>:: from_ne_bytes( self . 0 . to_ne_bytes( ) ) ;
976- // +0.0 and -0.0 differ only in the sign bit but compare equal
977- // under IEEE 754; normalize -0.0 → +0.0 so Hash agrees with Eq.
978- let bits: $i = if bits << 1 == 0 { 0 } else { bits } ;
979- state. write( & bits. to_ne_bytes( ) )
944+ state. write( & <$i>:: from_ne_bytes( self . 0 . to_ne_bytes( ) ) . to_ne_bytes( ) )
980945 }
981946 } ) +
982947 } ;
0 commit comments