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

Автор hungrytired, история, 6 лет назад, По-английски

I was trying out this question on AtCoder, https://atcoder.jp/contests/abc169/tasks/abc169_c. Actually in cpp i was doing double a = 9.79 and then long long b = 9.79*100 and weird thing b was assigned 978 not 979. I am confused why is this happening. If someone can put a blog link which might explain the problem further. Thanks a lot.

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +21 Проголосовать: не нравится

First $$$9.79$$$ is presented in $$$2$$$ power: $$$2^3 + 2^0 + ... + 2^{-x} + ... + 2^{-y} + ...$$$, and it is not exactly $$$9.79$$$ only approximate. Using $$$round(9.79 \cdot 100)$$$ instead.