Блог пользователя kphmd

Автор kphmd, 13 лет назад, По-английски

I guess the case "int(100*0.94) == 93" may be like this process:


         0.939999....
       _______________________
100 )94
        900
        ____
         400
         300
         _____
         1000
           900
           _____
          1000
            900
            _____
            1000
            ... ...
  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

13 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
I'm afraid that's for any compliant platform.

I mean, obviously the infinite binary fractions are truncated at some point. (Yet I cannot explicitly state how their last digit is obtained, sometimes it must be rounded down).

If ater that multiplication does not bring rounding up and happy disentegration of error, the numeric error is after us to haunt our dreams. Especially when we round it down to integer (and C/C++ casts with rounding down). In this case we obtained double with value <94. which shall be (and is) rounded to 93.

Your basic idea, gratefully explained to us with decimal example is right.