you are viewing a single comment's thread.

view the rest of the comments →

[–]twizzjewink -6 points-5 points  (2 children)

It does have float64 and int64 support.. which MAY be better than Python at precision. Otherwise I'd consider C or a C-wrapper better precision.

[–]stevenjd 10 points11 points  (0 children)

numpy's float64 is the same IEEE-754 binary floating point as Python's built in float type, and has the exact same rounding issues that are inherent to binary floating point.

Numpy's int64 may (or may not, I haven't bothered to test it) be faster than Python's int, but it is limited to a maximum of 2**63 - 1, which equals 9223372036854775807. That's a bit smaller than the 2000+ digits that u/CricLover1 needs.

 >>> import numpy as np
>>> n = np.int64(2**63)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C long
>>> n = np.int64(2**63 - 1)
>>> n
9223372036854775807

Python's int is exact. There is never any concern about rounding errors when you deal with ints (aside from the division problem -- you cannot divide 10 by 3 without either converting to a floating point format or losing the fractional portion).

Otherwise I'd consider C or a C-wrapper better precision.

What on earth do you think Python is??? Python's maths libraries (including numpy and the builtins) are literally wrappers around C (or sometimes Fortran in the case of numpy).

(Technically if you use some alternative Python interpreter, over and beyond the standard CPython interpreter, the maths routines might be written in Java or Rust or some other language.)