Ask Your Question
1

Arithmetic with large real numbers

asked 3 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 3 years ago

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.

Preview: (hide)
link

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: 3 years ago

Seen: 278 times

Last updated: Feb 09 '22