简体   繁体   中英

how to increase the round-off limit in python?

I wanted to know how to manually increase the round-0ff limit of a floating point number so that while performing power calculations, the output doesn't end up at 0.0 after a range of 0's

ex: math.pow(0.0000000000000001223,100)

0.0

I want the actual value of power calculation here..I wanted to perform math.log function from the output of the above calculation. But since its returning 0.0 i'm not able to perform log function. So how can i extend this round off limit value for once and for all ?? Is there any method to deal with this ??

Please help!!

expected output =

Instead of working hard in order to represent numbers beyond your architecture's basic capabilities, you can simply reformulate your calculation in a more numeric-friendly way:

log(x**100) --> 100*log(x)

You get:

x = 0.9
math.log(x**100)
=> -10.536051565782628
100*math.log(x)
=> -10.536051565782628

x = 0.0000000000000001223
math.log(x**100)
=> ValueError: math domain error
100 * math.log(x)
=> -3664.0054631199696

You can also use decimals :

>>>from decimal import Decimal
>>>Decimal(0.0000000000000001223)
>>>pow(n, 100)
Decimal('5.528988716402754783815478616E-1592')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM