1723377628

Calculate the logarithm of a number


If you need to calculate the logarithm of a number with php you can do this trick: ```php $log = log(5); //1.6094379124341 ``` For any arbitrary base logarithm, specify the base as a second optional parameter: ```php $log2 = log(16, 2); //4.0 ``` PHP supports the calculation of logarithms with its native Math extension. When you call log() without specifying a base, PHP will fall back on the default M_E constant, which is coded to the value of e, or approximately `2.718281828459`. If you try to take the logarithm of a negative value, PHP will always return NAN, a constant (typed as a float) that represents not a number. If you attempt to pass a negative base, PHP will return a ValueError and trigger a warning. Any positive, nonzero base is supported by `log()`. Many applications use base 10 so frequently that PHP supports a separate `log10()` function for just that base. This is functionally equivalent to passing the integer 10 as a base to `log()`.

(0) Comments

Welcome to Chat-to.dev, a space for both novice and experienced programmers to chat about programming and share code in their posts.

About | Privacy | Terms | Donate
[2024 © Chat-to.dev]