1

I was looking at the Golden Ratio formula for finding the nth Fibonacci number, and it made me curious.

I know Python handles arbitrarily large integers, but what sort of precision do you get with decimals? Is it just straight on top of a C double or something, or does it use a a more accurate modified implementation too? (Obviously not with arbitrary accuracy. ;D)

1
  • When you use the word "decimal" in the context of Python the usual assumption would be that you are referring to the decimal library which implements arbitrary precision arithmetic not at all comparable in accuracy to float or double. Commented Mar 6, 2024 at 5:05

2 Answers 2

3

almost all platforms map Python floats to IEEE-754 “double precision”.

http://docs.python.org/tutorial/floatingpoint.html#representation-error

there's also the decimal module for arbitrary precision floating point math

Sign up to request clarification or add additional context in comments.

Comments

2

Python floats use the double type of the underlying C compiler. As Bwmat says, this is generally IEEE-754 double precision.

However if you need more precision than that you can use the Python decimal module which was added in Python 2.4.

Python 2.6 also added the fraction module which may be a better fit for some problems.

Both of these are going to be slower than using the float type, but that is the price for more precision.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.