Skip to content

Conversation

@holiman
Copy link
Owner

@holiman holiman commented Mar 31, 2023

This PR implements

// CmpBig compares z and x and returns:
//
//	-1 if z <  x
//	 0 if z == x
//	+1 if z >  x
func (z *Int) CmpBig(x *big.Int) (r int) 

After some benchmarking, it turned out that converting from big to Int was not significantly slower than e.g pre-checking the BitLength, so I went with that in the end.

Closes #135

@codecov
Copy link

codecov bot commented Mar 31, 2023

Codecov Report

Merging #138 (93914f7) into master (71f8c05) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #138   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines         1615      1622    +7     
=========================================
+ Hits          1615      1622    +7     

@holiman
Copy link
Owner Author

holiman commented Mar 31, 2023

From CI run

BenchmarkCmpBig/nonequal-36               	82800283	        16.19 ns/op	       0 B/op	       0 allocs/op
BenchmarkCmpBig/equal-36                  	126040651	        10.66 ns/op	       0 B/op	       0 allocs/op

@holiman holiman merged commit 1c9ad56 into master Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Cmp to big.Int without converting big.Int

2 participants