log


expn apg

RETURN the Natural logarithm, (Napierian logarithm), of a given number or the logarithm of a given number in a given base.

Compatible with LOCALE only, up to PHP 7.4.XX.




This function return the natural logarithm of $num if the optional $base is not provided; however if $base provided this function will return the logarithm of $num in the $base.


<?php

float log 
float $numfloat $base M_E )


where,

$num The argument to process

$base 
The optional logarithmic base to use

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   M_E = e = 2.718281828459045235360287471352662497757247
               09369995957496696762772407663035354759457138
               21785251664274274663919320030599218174135966
               29043572900334295260595630738132328627943490
               76323382988075319525101901157383418793070215
               408...
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

?> 

$num


The value to calculate the logarithm for.



$base


The optional logarithmic base to use.

The default is e = M_E,
( the base of the natural logarithm ).



  1 EXERCISE   

<table width="100%" border="1" cellspacing="5" cellpadding="5">
<tr><td colspan="4">NATURAL LOGARITHM VALUES</td></tr>
<tr><td>CONSTANT</td><td>VALUE</td><td>OPERATION</td><td>RESULT</td></tr>
<?php

// setlocale(LC_ALL, 'pt-PT', 'pt_PT');

$l01_a = [ 'PHP_INT_MIN' => PHP_INT_MIN,
            
'PHP_FLOAT_MIN' => PHP_FLOAT_MIN,
            
'0' => 0'e' => M_E
            
'PHP_INT_MAX' => PHP_INT_MAX
            
'PHP_FLOAT_EPSILON' => PHP_FLOAT_EPSILON
            
'PHP_FLOAT_MAX' => PHP_FLOAT_MAX ];

foreach(
$l01_a as $wis => $val)


echo 
'<td>' $wis '</td>';
echo 
'<td>' $val '</td>';
echo 
'<td>log( ' $val ' )</td><td>' log($val) . '</td></tr>';

}

?>
<td colspan="4">ed48</td></tr></table>


  2 EXERCISE   

<table width="100%" border="1" cellspacing="5" cellpadding="5">
<tr><td colspan="4">BASE 10 LOGARITHM VALUES</td></tr>
<tr><td>CONSTANT</td><td>VALUE</td><td>OPERATION</td><td>RESULT</td></tr>
<?php

// setlocale(LC_ALL, 'pt-PT', 'pt_PT');

$l02_a = [ 'PHP_INT_MIN' => PHP_INT_MIN,
            
'PHP_FLOAT_MIN' => PHP_FLOAT_MIN,
            
'0' => 0'10' => 10
            
'PHP_INT_MAX' => PHP_INT_MAX
            
'PHP_FLOAT_EPSILON' => PHP_FLOAT_EPSILON
            
'PHP_FLOAT_MAX' => PHP_FLOAT_MAX ];

foreach(
$l02_a as $wis => $val)


echo 
'<td>' $wis '</td>';
echo 
'<td>' $val '</td>';
echo 
'<td>log( ' $val ', 10 )</td><td>' log($val10) . '</td></tr>';

}

?>
<td colspan="4">ed48</td></tr></table>


  3 EXERCISE   

<?php

// Run this code several times

// setlocale(LC_ALL, 'fr_FR', 'fr-FR', 'fr');
$base03 mt_rand(29);
?>
<table width="100%" border="1" cellspacing="5" cellpadding="5">
<tr><td colspan="4">VALEURS LOGARITHMES DE BASE <?php echo $base03?></td></tr>
<tr><td>CONSTANTE</td><td>VALEUR</td><td>OPERATION</td><td>RÉSULTAT</td></tr>
<?php

$l03_a 
= [ 'PHP_INT_MIN' => PHP_INT_MIN,
            
'PHP_FLOAT_MIN' => PHP_FLOAT_MIN,
            
'0' => 0'BASE' => $base03
            
'PHP_INT_MAX' => PHP_INT_MAX
            
'PHP_FLOAT_EPSILON' => PHP_FLOAT_EPSILON
            
'PHP_FLOAT_MAX' => PHP_FLOAT_MAX ];

foreach(
$l03_a as $wis => $val)


echo 
'<td>' $wis '</td>';
echo 
'<td>' $val '</td>';
echo 
'<td>log( ' $val ', ' $base03 ' )</td><td>' log($val$base03) . '</td></tr>';

}

?>
<td colspan="4">ed48</td></tr></table>