0

I'm a starter in x86 assembly. I'm about to divide 9 with 10 using below code, but I've got weird result.

.data
original real4 9.0
round DWORD 10

.code
(...)

fld original
fidiv round
fstp original

I expected the value 'original' would be 0.9, but the debugger says that 0.899999976.

What should I do to get 0.9 as a result?

  • You will need different floating value data type (like some SW emulated storing values in decimal-based encoding, maybe like string, etc), the HW accelerated IEEE-754 float/double can't hold value 0.9 exactly. Study more at http://floating-point-gui.de/ (or this joke sums it up nicely, if you understand how the thing works: https://www.reddit.com/r/ProgrammerHumor/comments/67oa29/the_secret_robot_internet/ ) – Ped7g Jun 14 '18 at 21:12
  • 1
    [Is floating point math broken?](https://stackoverflow.com/q/588004/995714) – phuclv Jun 15 '18 at 03:10

0 Answers0