简体   繁体   English

如何在python中增加舍入限制?

[英]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 我想知道如何手动增加浮点数的回合0ff限制,以便在执行功率计算时,在0的范围后输出不会以0.0结束

ex: math.pow(0.0000000000000001223,100) 例如: 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. 我想在这里获得功率计算的实际值。我想从上述计算的输出中执行math.log函数。 But since its returning 0.0 i'm not able to perform log function. 但是由于它返回0.0,所以我无法执行日志功能。 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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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