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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -