Working with very small numbers in python -
this question has answer here:
i using python , have this-
a=3.472556691305291e-97 b=2.0842803001689662e-120 c=a/(a+b) print(c) i getting value=1.0 . want exact answer.is there way can improve accuracy here?
you can use external library, such mpmath, arbitrary precision floating point numbers.
use mpf type numbers, shown in examples in documentation:
>>> mpf(4) mpf('4.0') >>> mpf(2.5) mpf('2.5') >>> mpf("1.25e6") mpf('1250000.0') >>> mpf(mpf(2)) mpf('2.0') >>> mpf("inf") mpf('+inf')
Comments
Post a Comment