Ask Your Question

Arithmetic with large real numbers

asked 2022-02-09 22:06:47 +0200

ant314159265 gravatar image

I would like to manipulate arbitrarily large real numbers, for example:

a = 10**25+.1
round(a) # expected: 10000000000000000000000000
sage: 10000000000000000905969664
a.is_integer() # expected: False
sage: True
a - 10**25 # expected: 0.1
sage: 0.000000000000000

What is the appropriate function to use?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-02-09 22:21:58 +0200

tmonteil gravatar image

You can define a "real field" with as many bits of precision as follows (the default is 53):

sage: R = RealField(100)
sage: R
Real Field with 100 bits of precision
sage: a = R(10^25) + R(0.1)
sage: a
sage: a.is_integer()

sage: a - 10**25

If you want a better result for that last question, just add more bits of precision.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2022-02-09 22:06:47 +0200

Seen: 35 times

Last updated: Feb 09