Skip to content Skip to sidebar Skip to footer

High Precision Arithmetric In Python And/or C/c++?

Abstract: Which Python package or C-Library is the best option for very high precision arithmetic operations? I have some functions which convert fractional days (0.0-0.99999..) to

Solution 1:

The difference is due to a bug in your code, not due to any accuracy issue. The line

output += self.nanosecond * (d(8.64) * d(10)**d(-9))

should be something like

output += self.nanosecond / d(86400000000000)

Furthermore, it is a Bad Idea to use floating point literals in your code and convert them to Decimal. This will first round the literal number to floating point accuracy. The later conversion to Decimal can't restore the lost accuracy. Try

d = decimal.Decimal

and use only integer literals (just remove the .0 part).

Solution 2:

CTRL-F "Libraries" there: Arbitrary-precision_arithmetic

EDIT: Extracting from the link libraries for c++ and python only (and removing some, that don't have floating numbers, but only integers)

python

1) mpmath


c++

1) apfloat

2) base one number class

3) bigfloat

4) lidia

5) mapm

6) MIRACL

7) NTL

8) ttmath

Post a Comment for "High Precision Arithmetric In Python And/or C/c++?"