1

Remix usually shows that floating points are not fully supported yet, and even the external libraries avaiable for floating point calculations in solidity are under the hood still using integers. So, is there any limitation as such when dealing with a decentralized computer which led to avoidance of typical floating points?

P.S: Recently started working with smart contracts on Tezos blockchain, and there too the floating point type is absent. This got me thinking if it might be the case for decentralized computers in general.

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 over nodes. Which would lead to forks.

In general I'd say it's because they are so tricky to implement. There are many different decimal formats for a bit different uses: doubles, float, decimals, ... And if something is tricky to implement it possibly also means it's tricky to execute which means high gas costs.

This is also probably restricted by the EVM in some fundamental way: some architectural decision early on which makes float implementation difficult.

However, there seems to be some willingness to implement them at some point. There is already a chapter about it: https://solidity.readthedocs.io/en/develop/types.html#fixed-point-numbers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.