@@ -663,8 +663,6 @@ got: {:?}",
663
663
} ,
664
664
665
665
Self :: Dcmp ( nan_handling) => {
666
- // TODO: Floating-point comparison in accordance with IEEE 754?
667
-
668
666
let op2 = if let StackValue :: Double ( d) =
669
667
frame. operand_stack . pop ( ) . unwrap ( )
670
668
{
@@ -680,24 +678,28 @@ got: {:?}",
680
678
panic ! ( "expected double on top" ) ;
681
679
} ;
682
680
683
- if op1. is_nan ( ) || op2. is_nan ( ) {
684
- match nan_handling {
685
- FloatCmp :: Pg => frame
686
- . operand_stack
687
- . push ( StackValue :: Int ( 1 ) )
688
- . unwrap ( ) ,
689
- FloatCmp :: Pl => frame
690
- . operand_stack
691
- . push ( StackValue :: Int ( -1 ) )
692
- . unwrap ( ) ,
681
+ match op1. partial_cmp ( & op2) {
682
+ Some ( Ordering :: Greater ) => {
683
+ frame. operand_stack . push ( StackValue :: Int ( 1 ) ) . unwrap ( ) ;
684
+ } ,
685
+ Some ( Ordering :: Equal ) => {
686
+ frame. operand_stack . push ( StackValue :: Int ( 0 ) ) . unwrap ( ) ;
687
+ } ,
688
+ Some ( Ordering :: Less ) => {
689
+ frame. operand_stack . push ( StackValue :: Int ( -1 ) ) . unwrap ( ) ;
690
+ } ,
691
+ None => {
692
+ match nan_handling {
693
+ FloatCmp :: Pg => frame
694
+ . operand_stack
695
+ . push ( StackValue :: Int ( 1 ) )
696
+ . unwrap ( ) ,
697
+ FloatCmp :: Pl => frame
698
+ . operand_stack
699
+ . push ( StackValue :: Int ( -1 ) )
700
+ . unwrap ( ) ,
701
+ }
693
702
}
694
- } else if op1 > op2 {
695
- frame. operand_stack . push ( StackValue :: Int ( 1 ) ) . unwrap ( ) ;
696
- } else if op1 == op2 {
697
- frame. operand_stack . push ( StackValue :: Int ( 0 ) ) . unwrap ( ) ;
698
- } else {
699
- // op1 < op2
700
- frame. operand_stack . push ( StackValue :: Int ( -1 ) ) . unwrap ( ) ;
701
703
}
702
704
703
705
Update :: None
@@ -973,41 +975,43 @@ got: {:?}",
973
975
} ,
974
976
975
977
Self :: Fcmp ( nan_handling) => {
976
- // TODO: Floating-point comparison in accordance with IEEE 754?
977
-
978
978
let op2 = if let StackValue :: Float ( d) =
979
979
frame. operand_stack . pop ( ) . unwrap ( )
980
980
{
981
981
d
982
982
} else {
983
- panic ! ( "expected double on top" ) ;
983
+ panic ! ( "expected float on top" ) ;
984
984
} ;
985
985
let op1 = if let StackValue :: Float ( d) =
986
986
frame. operand_stack . pop ( ) . unwrap ( )
987
987
{
988
988
d
989
989
} else {
990
- panic ! ( "expected double on top" ) ;
990
+ panic ! ( "expected float on top" ) ;
991
991
} ;
992
992
993
- if op1. is_nan ( ) || op2. is_nan ( ) {
994
- match nan_handling {
995
- FloatCmp :: Pg => frame
996
- . operand_stack
997
- . push ( StackValue :: Int ( 1 ) )
998
- . unwrap ( ) ,
999
- FloatCmp :: Pl => frame
1000
- . operand_stack
1001
- . push ( StackValue :: Int ( -1 ) )
1002
- . unwrap ( ) ,
993
+ match op1. partial_cmp ( & op2) {
994
+ Some ( Ordering :: Greater ) => {
995
+ frame. operand_stack . push ( StackValue :: Int ( 1 ) ) . unwrap ( ) ;
996
+ } ,
997
+ Some ( Ordering :: Equal ) => {
998
+ frame. operand_stack . push ( StackValue :: Int ( 0 ) ) . unwrap ( ) ;
999
+ } ,
1000
+ Some ( Ordering :: Less ) => {
1001
+ frame. operand_stack . push ( StackValue :: Int ( -1 ) ) . unwrap ( ) ;
1002
+ } ,
1003
+ None => {
1004
+ match nan_handling {
1005
+ FloatCmp :: Pg => frame
1006
+ . operand_stack
1007
+ . push ( StackValue :: Int ( 1 ) )
1008
+ . unwrap ( ) ,
1009
+ FloatCmp :: Pl => frame
1010
+ . operand_stack
1011
+ . push ( StackValue :: Int ( -1 ) )
1012
+ . unwrap ( ) ,
1013
+ }
1003
1014
}
1004
- } else if op1 > op2 {
1005
- frame. operand_stack . push ( StackValue :: Int ( 1 ) ) . unwrap ( ) ;
1006
- } else if op1 == op2 {
1007
- frame. operand_stack . push ( StackValue :: Int ( 0 ) ) . unwrap ( ) ;
1008
- } else {
1009
- // op1 < op2
1010
- frame. operand_stack . push ( StackValue :: Int ( -1 ) ) . unwrap ( ) ;
1011
1015
}
1012
1016
1013
1017
Update :: None
0 commit comments