How to find antilogarithm for large values?

3.3k views Asked by At

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.

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. so when I try to calculate (a*b) in Python It says long int too large to convert to 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.

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)?

1

There are 1 answers

4
Ned Batchelder On

If you need to calculate (10**x)%m, don't try to compute 10**x first. The pow function takes three arguments:

pow(x, y[, z])

Return x to the power y; if z is present, return x to the power y, modulo z (computed more efficiently than pow(x, y) % z). The two-argument form pow(x, y) is equivalent to using the power operator: x**y.

This seems perfect for your problem. You want pow(10, x, m)

OOPS: except you have a non-integral exponent.

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