Ask Your Question
1

Arithmetic with large real numbers

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

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
2

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

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
1.0000000000000000000000000100e25
sage: a.is_integer()
False

sage: a - 10**25
0.10000610351562500000000000000

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

Stats

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

Seen: 247 times

Last updated: Feb 09 '22