Tob*_*nne 2 largenumber r modulus integer-arithmetic
我有以下问题:
> 1e20 %% 3
[1] 0
Warning message:
probable complete loss of accuracy in modulus
Run Code Online (Sandbox Code Playgroud)
结果不可能是正确的,我确定这是因为1e20它真的很大。但我想在R. 有机会提出这个吗?
编辑:我想做以下挑战:https : //www.codeabbey.com/index/task_view/modular-calculator
这是我的代码:
library(tidyverse)
library(magrittr)
get_result <- function(.string){
terms <- .string %>%
str_split("\n") %>%
unlist %>%
str_replace("%", "%%") %>%
str_squish
terms[1] %<>%
str_c("x <<- ", .)
terms[2:length(terms)] %<>%
str_c("x <<- x ", .)
map(terms, ~ {
eval(parse(text = .x))
})
x
}
get_result("6
+ 12
* 99
+ 5224
* 53
* 2608
* 4920
+ 48
+ 7
* 54
* 4074
+ 76
* 2
* 97
+ 4440
+ 3
* 130
+ 432
* 50
* 1
+ 933
+ 3888
+ 600
+ 9634
* 10
* 59
+ 62
* 358
+ 82
+ 1685
* 78
+ 8
* 266
* 256
* 26
* 793
+ 1248
* 746
* 135
* 10
* 184
+ 4
* 502
* 60
+ 9047
* 5
+ 416
* 7
* 6287
* 8
% 4185")
Run Code Online (Sandbox Code Playgroud)
在我想使用模数之前,使用真实的测试数据我得到了一个巨大的数字