Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FloatingPointOperations.sol: Incorrect equality function #3

Open
hra687261 opened this issue Mar 18, 2022 · 0 comments
Open

FloatingPointOperations.sol: Incorrect equality function #3

hra687261 opened this issue Mar 18, 2022 · 0 comments

Comments

@hra687261
Copy link

In the FPO library in FloatingPointOperations.sol:

function eq(fraction a, fraction b) internal pure returns(bool) {
return ((a.nom == b.nom) && (a.denom == b.denom));
}

This equality function that checks if two fractions are equal is incorrect since it doesn't normalize the fractions before checking the equality.
Therefore, this function will return false if it is called on fraction(1,2) and fraction(2,4) while they are equal.
Also, after normalizing the fractions, the function should start by checking if the denominators are equal, that way, if they aren't, it won't be necessary to check if the numerators are equal, since the fraction will definitely not be equal.
There is also a warning from the TON-Solidity-Compiler that says that library functions should have default mutability.

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

No branches or pull requests

1 participant