1

In the EOS smart contract, it support the float point computation, such as calculating the voting weight.

And I think that, for different operation systems and different compilers, the float point procession could cause an inconsistent result.

So for different block producers, the data stored in their ram or database will be not same, and to the end, maybe we can't make the +2/3 producers to attrive the final conformation.

Is that right?

1 Answer 1

3

Yes, different platforms have inconsistent floating point arithmetic implementations wich could cause problems.

That is why EOS uses a C library which avoids hardware floating point calculations and brings consistency to those who require floating points.

The down side of this decision is of course performance, since software implementations are always slower than hardware solutions.

Using such a library at the core of the EOS system eliminates the need for each dApp developer who needs floating point calculations to include such a library for themselves. This would be wasteful and will force each dApp developer to "invent the wheel" repeatedly. Possibly coming up with different solutions. This is already happening in other dApp platforms which have integer only.

4
  • so when we use double in contract, we can get a definite result, right?
    – Jimmy Guo
    Commented Jul 12, 2018 at 8:12
  • Yes, the result will be the same each time. That's the reason for this decision.
    – Ami Heines
    Commented Jul 12, 2018 at 8:33
  • Thanks, and also another relative question, can I use the c function gettimeofday in contract? Because each producer will got different results, but I want to print the execution time for some code in the action, what can I do?
    – Jimmy Guo
    Commented Jul 12, 2018 at 9:36
  • Please open a new question on the site. This will keep this stackexchange site organized for future visitors. If you are satisfied with the answer, please mark it as complete.
    – Ami Heines
    Commented Jul 12, 2018 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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