简体   繁体   English

如何找到大数值的对数?

[英]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: 您不能使用以下等式:

  1. a**(b+c) == a**b * a**c
  2. (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.

相关问题 如何找到一系列n * 0.1(在Python中)最接近反对数(10base)的每个整数 - How to find every integer that is the closest to the antilogarithm (10base) for a series of n*0.1 (in Python) 如何在大型JSON文件中查找唯一值? - How to find unique values in a large JSON file? 在MongoDB中,如何找到大型分片集合的不同值? - In MongoDB, how do I find distinct values of a large, sharded collection? 如何在大 Pandas DataFrame 中找到“True”值对应的索引和列? - How to find the `True` values' corresponding index and column in a large Pandas DataFrame? 如何在 Python 的 6 列大数组中找到两个特定值? - How to find two specific values in a large 6-column array in Python? 如何从从 excel 文件派生的大量字典中的值列表中查找最小值和最大值 - How to find min and max values from list of values in large set of dictionary derived from excel file 如何在我的 numpy 数组中找到 NaN/无穷大/对于 dtype('float64') 来说太大的值? - How do I find the values in my numpy array that are NaN/infinity/too large for dtype('float64')? 如何使用python查找大型json文件的值中存在的所有单词 - How to find all the word present in a values of large json file using python 如何合并大量值 - How to bin large number of values Python-有效地从大型json文件中找到唯一值 - Python- find the unique values from a large json file efficienctly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM