Dealing with very small numbers in R

后端 未结 4 1256
花落未央
花落未央 2020-12-09 11:02

I need to calculate a list of very small numbers such as

(0.1)^1000, 0.2^(1200),

and then normalize them so they will sum up to one i.e.

a1 = 0.1^

4条回答
  •  星月不相逢
    2020-12-09 11:20

    The Brobdingnag package deals with very large or small numbers, essentially wrapping Joris's answer into a convenient form.

    a1 <- as.brob(0.1)^1000
    a2 <- as.brob(0.2)^1200
    a1_dash <- a1 / (a1 + a2)
    a2_dash <- a2 / (a1 + a2)
    as.numeric(a1_dash)
    as.numeric(a2_dash)
    

提交回复
热议问题