@@ -637,7 +637,7 @@ pub mod complex_im {
637
637
}
638
638
}
639
639
640
- macro_rules! cmp_impl {
640
+ macro_rules! eq_impl {
641
641
( $name: ident $eq: tt $ordering: expr) => {
642
642
pub mod $name {
643
643
use super :: * ;
@@ -650,11 +650,9 @@ macro_rules! cmp_impl {
650
650
pub fn num_num( a: f64 , b: f64 ) -> u8 {
651
651
( b. array_cmp( & a) $eq $ordering) as u8
652
652
}
653
-
654
653
pub fn com_x( a: Complex , b: impl Into <Complex >) -> u8 {
655
654
( b. into( ) . array_cmp( & a) $eq $ordering) as u8
656
655
}
657
-
658
656
pub fn x_com( a: impl Into <Complex >, b: Complex ) -> u8 {
659
657
( b. array_cmp( & a. into( ) ) $eq $ordering) as u8
660
658
}
@@ -679,8 +677,56 @@ macro_rules! cmp_impl {
679
677
} ;
680
678
}
681
679
682
- cmp_impl ! ( is_eq == std:: cmp:: Ordering :: Equal ) ;
683
- cmp_impl ! ( is_ne != Ordering :: Equal ) ;
680
+ macro_rules! cmp_impl {
681
+ ( $name: ident $eq: tt $ordering: expr) => {
682
+ pub mod $name {
683
+ use super :: * ;
684
+ pub fn always_greater<A , B >( _: A , _: B ) -> u8 {
685
+ ( $ordering $eq Ordering :: Less ) . into( )
686
+ }
687
+ pub fn always_less<A , B >( _: A , _: B ) -> u8 {
688
+ ( $ordering $eq Ordering :: Greater ) . into( )
689
+ }
690
+ pub fn num_num( a: f64 , b: f64 ) -> u8 {
691
+ ( b. array_cmp( & a) $eq $ordering) as u8
692
+ }
693
+ pub fn com_x( a: Complex , b: impl Into <Complex >) -> Complex {
694
+ let b = b. into( ) ;
695
+ Complex :: new(
696
+ ( b. re. array_cmp( & a. re) $eq $ordering) as u8 as f64 ,
697
+ ( b. im. array_cmp( & a. im) $eq $ordering) as u8 as f64
698
+ )
699
+ }
700
+ pub fn x_com( a: impl Into <Complex >, b: Complex ) -> Complex {
701
+ let a = a. into( ) ;
702
+ Complex :: new(
703
+ ( b. re. array_cmp( & a. re) $eq $ordering) as u8 as f64 ,
704
+ ( b. im. array_cmp( & a. im) $eq $ordering) as u8 as f64
705
+ )
706
+ }
707
+ #[ cfg( feature = "bytes" ) ]
708
+ pub fn byte_num( a: u8 , b: f64 ) -> u8 {
709
+ ( b. array_cmp( & f64 :: from( a) ) $eq $ordering) as u8
710
+ }
711
+ #[ cfg( feature = "bytes" ) ]
712
+ pub fn num_byte( a: f64 , b: u8 ) -> u8 {
713
+ ( f64 :: from( b) . array_cmp( & a) $eq $ordering) as u8
714
+ }
715
+ pub fn generic<T : Ord >( a: T , b: T ) -> u8 {
716
+ ( b. cmp( & a) $eq $ordering) . into( )
717
+ }
718
+ pub fn same_type<T : ArrayCmp + From <u8 >>( a: T , b: T ) -> T {
719
+ ( ( b. array_cmp( & a) $eq $ordering) as u8 ) . into( )
720
+ }
721
+ pub fn error<T : Display >( a: T , b: T , _env: & Uiua ) -> UiuaError {
722
+ unreachable!( "Comparisons cannot fail, failed to compare {a} and {b}" )
723
+ }
724
+ }
725
+ } ;
726
+ }
727
+
728
+ eq_impl ! ( is_eq == Ordering :: Equal ) ;
729
+ eq_impl ! ( is_ne != Ordering :: Equal ) ;
684
730
cmp_impl ! ( is_lt == Ordering :: Less ) ;
685
731
cmp_impl ! ( is_le != Ordering :: Greater ) ;
686
732
cmp_impl ! ( is_gt == Ordering :: Greater ) ;
0 commit comments