整数溢出与`R`

时间:2016-03-09 00:28:11

标签: r int integer-overflow int32 iranges

问题

我正在使用包[IRanges][1],我需要准确编码超过2 ^ 31超长10倍的超长序列。

从以下情况来看,似乎IRanges使用了int32

##### INSTALLATION FROM SRC CODE ######
## try http:// if https:// URLs are not supported
source("https://bioconductor.org/biocLite.R")
biocLite("IRanges")

##### CALL PACKAGE #####
require(IRanges)


IRanges(start=1,end=2^31-1) # Works fine

IRanges(start=1,end=2^31)   # Fail
Error in .Call2("solve_user_SEW0", start, end, width, PACKAGE = "IRanges") : 
  solving row 1: range cannot be determined from the supplied arguments (too many NAs)
In addition: Warning message:
In .normargSEW0(end, "end") : NAs introduced by coercion to integer range

由于这个包通常用于DNA序列,能够处理大于2 ^ 32(≈10^ 9)的值非常有用,因为许多生物的基因组大小比那些长。

问题

  • 我是否认为这是一个整数溢出问题?
  • 你遇到同样的问题吗?
  • 有没有解决这个问题的方法?
    • 是否可以(并且很容易)找到源代码并只修改对象类型
    • 你觉得这个包有另一个版本吗?

我找到的唯一解决方案就是接受降低我的准确度并将每个宽度除以100 ......但我对降低准确度并不满意。

R版

R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

1 个答案:

答案 0 :(得分:1)

您正在达到可以用R表示的整数大小的限制。

> .Machine$integer.max
#[1] 2147483647
> log2(.Machine$integer.max)
#[1] 31

有一些特殊的库,如bit64gmp,可用于处理例如64位有符号整数。但是,它不确定这些包所代表的整数是否与其他库兼容。