Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double precision floating values in Python?

Are there data types with better precision than float?

like image 663
kravemir Avatar asked Jul 12 '11 11:07

kravemir


People also ask

Is 1.5 float or double?

And the reason the comparison succeeds with 1.5 is that 1.5 can be represented exactly as a float and as a double ; it has a bunch of zeros in its low bits, so when the promotion adds zeros the result is the same as the double representation.

Is Python float 32 or 64?

Python's floating-point numbers are usually 64-bit floating-point numbers, nearly equivalent to np.

Is float double precision?

A variable of type float only has 7 digits of precision whereas a variable of type double has 15 digits of precision. If you need better accuracy, use double instead of float.

Is 1.2 float or double?

1.2 is a double (8 bytes). 1.2f is a float (4 bytes). Show activity on this post. Any literal number in your code which includes a decimal point is interpreted as a double , not a float , unless you mark it as a float by appending f .


1 Answers

Python's built-in float type has double precision (it's a C double in CPython, a Java double in Jython). If you need more precision, get NumPy and use its numpy.float128.

like image 103
Fred Foo Avatar answered Oct 13 '22 20:10

Fred Foo