number theory - Unwanted warnings in R VeryLargeIntegers package - Stack Overflow

I am getting an unwanted warning message when doing division using the R package VeryLargeIntegers, but

I am getting an unwanted warning message when doing division using the R package VeryLargeIntegers, but just for a very specific choice of numbers. The actual output seems to be correct, but the warning message is distracting at best, and worrisome in case something important is really happening. I came across this situation doing some number theory coding.

# Example of an apparent bug in the VeryLargeIntegers package

# Division gives an unwanted warning for one particular choice of numbers,
# and the situation propagates to a number of other functions.

require(VeryLargeIntegers)
#> Loading required package: VeryLargeIntegers
require(reprex)
#> Loading required package: reprex
sessionInfo()
#> R version 4.4.3 (2025-02-28 ucrt)
#> Platform: x86_64-w64-mingw32/x64
#> Running under: Windows 11 x64 (build 26100)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.utf8 
#> [2] LC_CTYPE=English_United States.utf8   
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.utf8    
#> 
#> time zone: America/Los_Angeles
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] reprex_2.1.1            VeryLargeIntegers_0.2.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] digest_0.6.37     fastmap_1.2.0     xfun_0.51         glue_1.8.0       
#>  [5] knitr_1.50        htmltools_0.5.8.1 rmarkdown_2.29    lifecycle_1.0.4  
#>  [9] cli_3.6.4         withr_3.0.2       compiler_4.4.3    rstudioapi_0.17.1
#> [13] tools_4.4.3       evaluate_1.0.3    Rcpp_1.0.14       yaml_2.3.10      
#> [17] rlang_1.1.5       fs_1.6.5

##      Ordinary division code that works
1000003 %% 4  # gets the remainder
#> [1] 3
1000003 %/% 4 # gets the integer part of the division
#> [1] 250000

## Now use the .vli type

# In all these examples the computation appears to be correct, but there is
# an unwanted warning message

four <- as.vli(4)
bigprime <- as.vli(1000003)

# Division
bigprime %% four # gets the remainder
#> Warning in divbaseC(x, y): subscript out of bounds (index 1 >= vector size 1)
#> Very Large Integer: 
#> [1] 3
bigprime/four # gets the integer part of the quotient
#> Warning in divbaseC(x, y): subscript out of bounds (index 1 >= vector size 1)
#> Very Large Integer: 
#> [1] 250000


# Other functions in the VeryLargeIntegers package

## The situation propagates to other functions in the VeryLargeIntegers package
# Greatest common divisor -- correct answer is 1
gcd(4, 1000003) 
#> Warning in divbaseC(y, x): subscript out of bounds (index 1 >= vector size 1)
#> Very Large Integer: 
#> [1] 1
gcd(four, bigprime)
#> Warning in divbaseC(y, x): subscript out of bounds (index 1 >= vector size 1)
#> Very Large Integer: 
#> [1] 1

# Jacobi symbol -- correct answer is 1, since 4 is obviously a square
Jacobi(4, 1000003)
#> Warning in divbaseC(a, .pkgenv$four): subscript out of bounds (index 1 >=
#> vector size 1)
#> Very Large Integer: 
#> [1] 1
Jacobi(four, bigprime)
#> Warning in divbaseC(a, .pkgenv$four): subscript out of bounds (index 1 >=
#> vector size 1)
#> Very Large Integer: 
#> [1] 1

## There seems to be sensitivity to the number 4. The following all work with no warnings.

bigprime %% 2
#> Very Large Integer: 
#> [1] 1
bigprime %% 8
#> Very Large Integer: 
#> [1] 3
bigprime %% 16
#> Very Large Integer: 
#> [1] 3

Created on 2025-03-20 with reprex v2.1.1

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744379284a4571344.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信