# Tag Info

16

Disclaimer: I am the author of PRBMath. Fixed-Point PRBMath signed and unsigned denary numbers with 18 decimals of precisions offers advanced math functions (logs, exp, pow, etc.) bakes in overflow-safe multiplication and division ultra gas efficient ABDKMath64x64 binary numbers with 2^64 precision offers advanced math functions (logs, exp, pow, etc.) ...

2

I thought I read some rationale behind this somewhere a long time ago but can't find it anymore. Anyway. This is mainly a restriction of the EVM, not so much of Solidity. One reason I found (https://ethereum.stackexchange.com/a/58751/31933): The obvious reason is that floats are, by nature, unpredictable, which would make the outcome of operations different ...

1

The compiler does accept decimals in an expression if the resulting value is valid. For example uint256 x = 0.23 * 100 is valid. The expression uint256 y = 0.123 * 100 fails to compile with TypeError: Type rational_const 123 / 10 is not implicitly convertible to expected type uint256.

1

Do first the multiplications and then divide: (voteCount*100/adminCount) > 50 In the case of 2 votes and 3 admins you will get 200/3 = 66 > 50 If you need more resolution (decimals) you can add a multiplier to both side of the inequality, for instance: decimals: 2; (voteCount*100*(10**decimals)/adminCount) > 50*(10**decimals) Again in the case of ...

1

When I try to run this code on remix it gave UnimplementedFeatureError: Not yet implemented - FixedPointType. Which you can see here This is not possible to use uint(3/30) as you are doing. Casting of any floating point using uint is not acceptable. The Fixed Point are not yet unuseable in solidity as it documentation says: Fixed point numbers are not ...

1

In my opinion, it is preferable to adapt to the EVM's use of integers where possible. It is nearly always possible. For example, here is a simple pattern for handling a percentage with two high-precision integers (one could be an exchange rate and the other a transaction volume). First, convert each input to an 18-decimal integer. So 1.0 would be 1 * 10 ** ...

Only top voted, non community-wiki answers of a minimum length are eligible