LoginSignup
4
3

More than 5 years have passed since last update.

[Ruby]単純な計算結果がおかしい

Last updated at Posted at 2016-01-14

どうでもいい話ですが、Ubuntu で ruby 1.9.3p484 使ってて単純な計算結果が変であることに気づく。何で?丸め誤差?

xxxxx@titan:~$ uname -a
Linux titan 3.13.0-74-generic #118-Ubuntu SMP Thu Dec 17 22:52:02 UTC 2015 i686 i686 i686 GNU/Linux
xxxxx@titan:~$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [i686-linux]
xxxxx@titan:~$ ruby -e 'puts 1.1*2.2'
2.4200000000000004
xxxxx@titan:~$ ruby -e 'puts 1.1*2.2*3.3'
7.986000000000001
xxxxx@titan:~$ 
4
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3