我最近在推特上看到this,开始想知道发生了什么事。
我阅读了seq document,但是无法理解为什么seq(from = -1.4,to = 1.4,by = 0.2)不会产生-1.4,-1.2,-1.0 .... / p>
有什么主意吗?
符合预期
i <- seq(from=-1.5,to=1.5, by=0.2)
format(i, scientific = F)
#> [1] "-1.5" "-1.3" "-1.1" "-0.9" "-0.7" "-0.5" "-0.3" "-0.1" " 0.1" " 0.3"
#> [11] " 0.5" " 0.7" " 0.9" " 1.1" " 1.3" " 1.5"
意外
i <- seq(from=-1.4,to=1.4, by=0.2)
format(i, scientific = F)
#> [1] "-1.3999999999999999111822" "-1.1999999999999999555911"
#> [3] "-0.9999999999999998889777" "-0.7999999999999998223643"
#> [5] "-0.5999999999999998667732" "-0.3999999999999999111822"
#> [7] "-0.1999999999999997335465" " 0.0000000000000002220446"
#> [9] " 0.2000000000000001776357" " 0.4000000000000001332268"
#> [11] " 0.6000000000000000888178" " 0.8000000000000002664535"
#> [13] " 1.0000000000000004440892" " 1.2000000000000001776357"
#> [15] " 1.3999999999999999111822"