为什么R将大数视为偶数 [英] Why does R regard large number as EVEN

查看:107
本文介绍了为什么R将大数视为偶数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从" http: //cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-the " 7.31

From "http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-the" 7.31

我们已经知道,大数(超过2 ^ 53)会在模块化操作中产生错误.

We already know that large number (over 2^53) can make an error in modular operation.

但是,即使我有一些近似误差,我也无法理解为什么所有的大数都被视为偶数(我从未见过大于2 ^ 53的大整数的奇数")

However, I cannot understand why all the large number is regarded as even(I have never seen "odd" of large integer which is over 2^53) even though I take some errors in approximation

(2^53+1)%%2
(2^100-1)%%2

错误消息(模数精度可能完全丧失)可以忽略

error message(probable complete loss of accuracy in modulus) can be ignored

等.

不是1而是0

为什么呢? (我知道有一些近似值,但是我需要具体知道原因)

why so? (I know there is some approximation, but I need to know the reason concretely)

> print(2^54,22)
[1] 18014398509481984.00000 
> print(2^54+1,22)
[1] 18014398509481984.00000 
> print(2^54+2,22) 
[1] 18014398509481984.00000 
> print(2^54+3,22) 
[1] 18014398509481988.0000

推荐答案

一个 IEEE双精度值具有53位尾数.需要精度超过53个二进制数字的任何数字都将四舍五入,即从54开始的数字将隐式设置为零.因此,任何大小大于2 ^ 53的数字都将是偶数(因为其整数表示的最低有效位超出了浮点精度,因此为零).

An IEEE double precision value has a 53-bit mantissa. Any number requiring more than 53 binary digits of precision will be rounded, i.e. the digits from 54 onwards will be implicitly set to zero. Thus any number with magnitude greater than 2^53 will necessarily be even (since the least-significant bit of its integer representation is beyond the floating-point precision, and is therefore zero).

这篇关于为什么R将大数视为偶数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆