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).
Post a Comment for "High Precision Arithmetric In Python And/or C/c++?"