0

So I've made this function

def log(x,base):
    result = ln(x)/ln(base)
    return result

except it needs the natural log and the natural log is an entire can of worms on its own so is there any other way to find the log of something without using the natural logarithm or any pre-existing methods?

def log(x,base):
    result = ln(x)/ln(base)
    return result

This function is slightly imprecise which causes issues elsewhere. Example: if an input of (4,2) is given it returns 2.0000003203426897, close but not exactly correct.

  • 1
    Python already has [`log`](https://docs.python.org/3/library/math.html#math.log). See also https://stackoverflow.com/q/588004/3001761. – jonrsharpe Jan 16 '23 at 11:02
  • You write *"the natural log is an entire can of worms"*. Well, that's peanuts compared to opening the can of worms when trying to write your own code for such a numeric computation. By the way, I don't understand where you the library functions used in your test. `np.log(4) / np.log(2)` and `math.log(4) / math.log(2)` both output exactly `2.0`. – JohanC Jan 16 '23 at 15:56

0 Answers0