0

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

  • how large? How much precision? – President James K. Polk Nov 16 '14 at 16:28
  • x will be around 1500... I'm not sure, but minimum value of x will be around 700 (as It is calculated in an intermediate step of my question, so I'm not that much sure about It). Precision doesn't matter as finally I want my answer to be integer, but that should round of to correct integer. – Prakhar Awasthi Nov 16 '14 at 16:34

1 Answers1

1

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
Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662