在R,为什么typeof(Inf)
返回double
? R认为Infinity是实数还是只是数字?
x=1
xx=0
y=x/xx
typeof(y)
答案是"double"
谢谢
一般来说,因为R中的任何数字文字都有double
类型,除非它以L
结尾:
> typeof(1)
double
> typeof(NA_real_)
double
> typeof(1L)
integer
更具体地说,因为Inf
is a special value that can only be stored in a floating-point number,不是整数。