Skip to content

solidity exp() differs from javascript sdk exp() #109

Closed Answered by PaulRBerg
antoniopgs asked this question in Q&A
Discussion options

You must be logged in to vote

Assuming that you used evm-bn, and the intention was to raise to power 0.000003174150177198 (3174150177198 in Solidity), then the behavior you're observing is completely expected.

It is not possible (or just very difficult) to have exact parity between mathematical functions implemented in different programming languages. And in our case, we are confronted with two very different languages: Solidity and JavaScript.

If you're writing Hardhat tests, you shouldn't check for exact equality between outputs. Instead, you should use an assertion such as Waffle's closeTo, or the one I wrote for PRBMath itself, the near assertion.

It might be instructive to take a look at the tests I have written …

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
2 replies
@antoniopgs
Comment options

@PaulRBerg
Comment options

Comment options

You must be logged in to vote
6 replies
@PaulRBerg
Comment options

@antoniopgs
Comment options

@antoniopgs
Comment options

@PaulRBerg
Comment options

@antoniopgs
Comment options

Answer selected by antoniopgs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants