[英]How to find antilogarithm for large values?
I want to know how to find antilogarithm of a float. 我想知道如何找到浮点数的对数。 My first approach was to use built-in functions like exp(), pow() both in Python & C, but they gave out of range error.
我的第一种方法是在Python和C中都使用内置函数,例如exp(),pow(),但它们给出了超出范围的错误。
Then I tried to break It in two parts, one integer & other float, then calculate 10 raise to the power separately for both of them & then multiply them to get the result. 然后,我尝试将其分为两个部分,一个整数和另一个浮点数,然后分别为它们计算10提高到幂的乘积,然后将它们相乘得到结果。 so when I try to calculate (a*b) in Python It says long int too large to convert to float
因此,当我尝试在Python中计算(a * b)时,它说long int太大,无法转换为float
My Original task was to calculate antilog(x)%m & I converted it (a*b)%m where a is very very large integer & b is float. 我的原始任务是计算antilog(x)%m,然后将其转换为(a * b)%m,其中a是非常大的整数,b是浮点型。
So can anyone help me out with this? 那么有人可以帮我吗? Is there any modular property that applies on floats?
是否有适用于浮点数的模块化属性? Or is there any "fast" & "efficient" way to calculate antilog(x)?
还是有任何“快速”和“有效”的方式来计算antilog(x)?
If you need to calculate (10**x)%m
, don't try to compute 10**x
first. 如果您需要计算
(10**x)%m
,请不要尝试先计算10**x
。 The pow function takes three arguments: pow函数采用三个参数:
pow(x, y[, z])
pow(x,y [,z])
Return x to the power y;
将x返回到幂y; if z is present, return x to the power y, modulo z (computed more efficiently than pow(x, y) % z).
如果存在z,则将x乘以z模的幂(比pow(x,y)%z更有效地计算)。 The two-argument form pow(x, y) is equivalent to using the power operator: x**y.
二元形式pow(x,y)等效于使用幂运算符:x ** y。
This seems perfect for your problem. 这似乎很适合您的问题。 You want
pow(10, x, m)
你要
pow(10, x, m)
OOPS: except you have a non-integral exponent. OOPS:除了您有非整数指数。
Can't you use these equalities: 您不能使用以下等式:
a**(b+c) == a**b * a**c
(a*b)%m == (a%m * b%m) % m
to define a function like this: 定义这样的函数:
def bigpow(a, b, m):
bint = int(b)
bfrac = b - int(b)
return (pow(a, bint, m) * ((a**bfrac)%m)) % m
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.