3

Floats and floating point operations are very useful in different applications. I know that they are not officially supported, nonetheless it would be possible to implement floats as for example explained here https://en.wikipedia.org/wiki/Floating-point_arithmetic

Besides the necessary amount of storage, what else prevents floats on ethereum?

2

I think there is no technical hurdle but the problem is about the accuracy(rounding problems,..) while we are dealing with money nor a normal system. The better alternative is to use a fixed point with a small undevided unit like wei in the etherum case. Read about rounding problems in finance: https://stackoverflow.com/questions/3840793/rounding-standards-financial-calculations

1
  • Thanks for the hint to rounding standards. My question arises from the idea to use the EVM for light computations in a hierarchical optimization scheme, where floats would be more accurate. I will try using fixed point numbers.
    – Lukas M
    May 12 '17 at 8:48
0

I think the main reason is that all operations in Ethereum have to be deterministic. For integer numbers it is easy to define what is x * y, or x / y exactly. For floating points it is much harder, but still possible. The problem is that all implementation has to guarantee that all floating point calculations return exactly what they should, even if native operations implemented in CPU behave differently.

I agree with @Badr that fixed point arithmetic seems to be more promising, because it is based on integer operations. Solidity still does not fully support fixed point, but there are libraries for them such as ABDK Math 64.64 library.

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.