Work with large numbers in R [Inf] and Python

I am learning Python these days, and this is probably my first post in Python. I am relatively new to R, and have also used R for about a year. I compare both languages ​​while learning Python. I apologize if this question is too simple.

I'm not sure why R is outputting Infpython for something. Take as an example 2^1500.

In R:

nchar(2^1500)
[1] 3
2^1500
[1] Inf

In Python:

len(str(2**1500))
Out[7]: 452
2**1500
Out[8]: 3507466211043403874...

I have two questions:

a) Why R provides Infwhen Python does not.

b) I researched How to work with large numbers in the stream R? . It seems that it Brobdingnagcan help us deal with large numbers. However, even in this case, I cannot calculate nchar. How to calculate the above expression, i.e. 2 ^ 1500 to R

2^Brobdingnag::as.brob(500)
[1] +exp(346.57)
> nchar(2^Brobdingnag::as.brob(500))
Error in nchar(2^Brobdingnag::as.brob(500)) : 
  no method for coercing this S4 class to a vector
+6
2

:

a) . R . 64 15- , -double.xmax double.xmax, . R 32- . +/- 2 . R , , , . ( , .)

Python - , , MichaelChirico.

b) Brobdingnag, gmp . ,

> as.bigz(2)^1500
Big Integer ('bigz') :
[1] 35074662110434038747627587960280857993524015880330828824075798024790963850563322203657080886584969261653150406795437517399294548941469959754171038918004700847889956485329097264486802711583462946536682184340138629451355458264946342525383619389314960644665052551751442335509249173361130355796109709885580674313954210217657847432626760733004753275317192133674703563372783297041993227052663333668509952000175053355529058880434182538386715523683713208549376
> nchar(as.character(as.bigz(2)^1500))
[1] 452

, as.character() Brobdingnag.

+6

-, python . R . R-. , .

, , Rmpfr:

> library(Rmpfr)
> a <- 2^mpfr(1500, 10000)
> a
1 'mpfr' number of precision  10000   bits 
[1] 35074662110434038747627587960280857993524015880330828824075798024790963850563322203657080886584969261653150406795437517399294548941469959754171038918004700847889956485329097264486802711583462946536682184340138629451355458264946342525383619389314960644665052551751442335509249173361130355796109709885580674313954210217657847432626760733004753275317192133674703563372783297041993227052663333668509952000175053355529058880434182538386715523683713208549376

, , 2 ^ 1500 .

as.character():

> as.character(a)
[1] "<S4 object of class \"mpfr1\">"

, , , , , gmp, . , , Rmpfr .

+5

All Articles