Skip to content

Commit 0efc045

Browse files
committed
add cmp ops
1 parent 8a8f2c1 commit 0efc045

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

int.go

+80
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,46 @@ func (u128 U128) Equal(other U128) bool {
599599
return u128.inner.Cmp(other.inner) == 0
600600
}
601601

602+
func (u128 U128) LessThan(other U128) bool {
603+
if u128.inner == nil {
604+
return other.inner != nil && other.inner.Sign() > 0
605+
}
606+
if other.inner == nil {
607+
return u128.inner != nil && u128.inner.Sign() < 0
608+
}
609+
return u128.inner.Cmp(other.inner) < 0
610+
}
611+
612+
func (u128 U128) LessThanEqual(other U128) bool {
613+
if u128.inner == nil {
614+
return other.inner != nil && other.inner.Sign() >= 0
615+
}
616+
if other.inner == nil {
617+
return u128.inner != nil && u128.inner.Sign() <= 0
618+
}
619+
return u128.inner.Cmp(other.inner) <= 0
620+
}
621+
622+
func (u128 U128) GreaterThan(other U128) bool {
623+
if u128.inner == nil {
624+
return other.inner != nil && other.inner.Sign() < 0
625+
}
626+
if other.inner == nil {
627+
return u128.inner != nil && u128.inner.Sign() > 0
628+
}
629+
return u128.inner.Cmp(other.inner) > 0
630+
}
631+
632+
func (u128 U128) GreaterThanEqual(other U128) bool {
633+
if u128.inner == nil {
634+
return other.inner != nil && other.inner.Sign() <= 0
635+
}
636+
if other.inner == nil {
637+
return u128.inner != nil && u128.inner.Sign() >= 0
638+
}
639+
return u128.inner.Cmp(other.inner) >= 0
640+
}
641+
602642
func (u128 U128) SizeHint() int {
603643
return 16
604644
}
@@ -811,6 +851,46 @@ func (u256 U256) Equal(other U256) bool {
811851
return u256.inner.Cmp(other.inner) == 0
812852
}
813853

854+
func (u256 U256) LessThan(other U256) bool {
855+
if u256.inner == nil {
856+
return other.inner != nil && other.inner.Sign() > 0
857+
}
858+
if other.inner == nil {
859+
return u256.inner != nil && u256.inner.Sign() < 0
860+
}
861+
return u256.inner.Cmp(other.inner) < 0
862+
}
863+
864+
func (u256 U256) LessThanEqual(other U256) bool {
865+
if u256.inner == nil {
866+
return other.inner != nil && other.inner.Sign() >= 0
867+
}
868+
if other.inner == nil {
869+
return u256.inner != nil && u256.inner.Sign() <= 0
870+
}
871+
return u256.inner.Cmp(other.inner) <= 0
872+
}
873+
874+
func (u256 U256) GreaterThan(other U256) bool {
875+
if u256.inner == nil {
876+
return other.inner != nil && other.inner.Sign() < 0
877+
}
878+
if other.inner == nil {
879+
return u256.inner != nil && u256.inner.Sign() > 0
880+
}
881+
return u256.inner.Cmp(other.inner) > 0
882+
}
883+
884+
func (u256 U256) GreaterThanEqual(other U256) bool {
885+
if u256.inner == nil {
886+
return other.inner != nil && other.inner.Sign() <= 0
887+
}
888+
if other.inner == nil {
889+
return u256.inner != nil && u256.inner.Sign() >= 0
890+
}
891+
return u256.inner.Cmp(other.inner) >= 0
892+
}
893+
814894
func (u256 U256) SizeHint() int {
815895
return 32
816896
}

0 commit comments

Comments
 (0)