{"id":59,"date":"2019-08-30T19:23:02","date_gmt":"2019-08-30T19:23:02","guid":{"rendered":"https:\/\/tutorialio.com\/?p=59"},"modified":"2019-08-30T19:23:02","modified_gmt":"2019-08-30T19:23:02","slug":"exponential-and-logarithmic-functions-in-php","status":"publish","type":"post","link":"https:\/\/hellonitish.com\/blog\/exponential-and-logarithmic-functions-in-php\/","title":{"rendered":"Exponential and Logarithmic Functions in PHP"},"content":{"rendered":"<table class=\"quick-links\">\n<caption>Random Number Functions Functions in PHP<\/caption>\n<\/caption>\n<tbody>\n<tr>\n<th>Function Name<\/th>\n<th>Function Description<\/th>\n<\/tr>\n<tr>\n<td><a href=\"#exp\">exp()<\/a><\/td>\n<td>Calculates the exponent of e<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#expm1\">expm1()<\/a><\/td>\n<td>Returns exp(number) &#8211; 1, computed in a way that is accurate even when the value of number is close to zero<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#log10\">log10()<\/a><\/td>\n<td>Base-10 logarithm<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#log1p\">log1p()<\/a><\/td>\n<td>Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#log\">log()<\/a><\/td>\n<td>Natural logarithm<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#pow\">pow()<\/a><\/td>\n<td>Exponential expression<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#sqrt\">sqrt()<\/a><\/td>\n<td>Square root<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"exp\">PHP <code>exp()<\/code> Function<\/h2>\n<h3>PHP <code>exp()<\/code> Usage<\/h3>\n<p>The PHP <code><code>exp()<\/code><\/code> function will give you <code>e<\/code> raised to the power of <code class=\"parameter\">arg<\/code>.<\/p>\n<h3>PHP <code>exp()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> exp ( float $arg ) : float<\/code><\/pre>\n<h3>PHP <code>exp()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>arg<\/code> \u2014 The argument to process <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>exp()<\/code> Return Value<\/h3>\n<p>The PHP <code>exp()<\/code> function returns &#8216;e&#8217; raised to the power of <code class=\"parameter\">arg<\/code><\/p>\n<h3>PHP <code>exp()<\/code> Working Examples<\/h3>\n<h4>1. exp() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\necho exp(12) . \"\\n\";\necho exp(5.7);\n?&gt;<\/code><\/pre>\n<p>Output of the above code:<\/p>\n<pre><code class=\"lang-php\">1.6275E+005\n298.87<\/code><\/pre>\n<h3>Important Points about PHP <code>exp()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> &#8216;<code>e<\/code>&#8216; is the base of the natural system of logarithms, or approximately 2.718282. <\/p>\n<\/li>\n<\/ol>\n<h2 id=\"expm1\">PHP <code>expm1()<\/code> Function<\/h2>\n<h3>PHP <code>expm1()<\/code> Usage<\/h3>\n<p>The PHP <code><code>expm1()<\/code><\/code> function will give you exp(number) &#8211; 1, computed in a way that is accurate even when the value of number is close to zero .<\/p>\n<h3>PHP <code>expm1()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> expm1 ( float $arg ) : float<\/code><\/pre>\n<h3>PHP <code>expm1()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>arg<\/code> \u2014 The argument to process <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>expm1()<\/code> Return Value<\/h3>\n<p>The PHP <code>expm1()<\/code> function returns &#8216;e&#8217; to the power of <code class=\"parameter\">arg<\/code> minus one<\/p>\n<h3>Changelog for PHP expm1()<\/code> Function<\/h3>\n<p><strong>5.3.0 \u2014 <\/strong> This function is now available on all platforms <\/p>\n<h2 id=\"log10\">PHP <code>log10()<\/code> Function<\/h2>\n<h3>PHP <code>log10()<\/code> Usage<\/h3>\n<p>The PHP <code><code>log10()<\/code><\/code> function will give you the base-10 logarithm of <code class=\"parameter\">arg<\/code>.<\/p>\n<h3>PHP <code>log10()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> log10 ( float $arg ) : float<\/code><\/pre>\n<h3>PHP <code>log10()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>arg<\/code> \u2014 The argument to process <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>log10()<\/code> Return Value<\/h3>\n<p>The PHP <code>log10()<\/code> function returns the base-10 logarithm of <code class=\"parameter\">arg<\/code><\/p>\n<h2 id=\"log1p\">PHP <code>log1p()<\/code> Function<\/h2>\n<h3>PHP <code>log1p()<\/code> Usage<\/h3>\n<p>The PHP <code><code>log1p()<\/code><\/code> function will give you log(1 + number), computed in a way that is accurate even when the value of number is close to zero .<\/p>\n<h3>PHP <code>log1p()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> log1p ( float $number ) : float<\/code><\/pre>\n<h3>PHP <code>log1p()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>number<\/code> \u2014 The argument to process <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>log1p()<\/code> Return Value<\/h3>\n<p>The PHP <code>log1p()<\/code> function returns log(1 + <code class=\"parameter\">number<\/code>)<\/p>\n<h3>Changelog for PHP log1p()<\/code> Function<\/h3>\n<p><strong>5.3.0 \u2014 <\/strong> This function is now available on all platforms <\/p>\n<h2 id=\"log\">PHP <code>log()<\/code> Function<\/h2>\n<h3>PHP <code>log()<\/code> Usage<\/h3>\n<p>The PHP <code><code>log()<\/code><\/code> function will give you logbase <code class=\"parameter\">arg<\/code>, otherwise <code>log()<\/code> return the natural logarithm of <code class=\"parameter\">arg<\/code>.<\/p>\n<h3>PHP <code>log()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> log ( float $arg [, float $base = M_E ] ) : float<\/code><\/pre>\n<h3>PHP <code>log()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>arg<\/code> \u2014 The value to calculate the logarithm for <\/p>\n<\/li>\n<li>\n<p><code>base<\/code> \u2014 The optional logarithmic base to use (defaults to &#8216;e&#8217; and so to the natural logarithm). <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>log()<\/code> Return Value<\/h3>\n<p>The PHP <code>log()<\/code> function returns the logarithm of <code class=\"parameter\">arg<\/code> to <code class=\"parameter\">base<\/code>, if given, or the natural logarithm.<\/p>\n<h2 id=\"pow\">PHP <code>pow()<\/code> Function<\/h2>\n<h3>PHP <code>pow()<\/code> Usage<\/h3>\n<p>The PHP <code><code>pow()<\/code><\/code> function will give you <code class=\"parameter\">base<\/code> raised to the power of <code class=\"parameter\">exp<\/code>.<\/p>\n<h3>PHP <code>pow()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> pow ( number $base , number $exp ) : number<\/code><\/pre>\n<h3>PHP <code>pow()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>base<\/code> \u2014 The base to use <\/p>\n<\/li>\n<li>\n<p><code>exp<\/code> \u2014 The exponent <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>pow()<\/code> Return Value<\/h3>\n<p>The PHP <code>pow()<\/code> function returns d with integer type, otherwise it will be returned as a float.<\/p>\n<h3>PHP <code>pow()<\/code> Working Examples<\/h3>\n<h4>1. Some examples of pow()<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\nvar_dump(pow(2, 8)); \/\/ int(256)\necho pow(-1, 20); \/\/ 1\necho pow(0, 0); \/\/ 1\necho pow(10, -1); \/\/ 0.1\necho pow(-1, 5.5); \/\/ PHP &gt;=5.2.2: NAN\necho pow(-1, 5.5); \/\/ PHP &lt;5.2.2: -NAN\n?&gt;<\/code><\/pre>\n<h3>Important Points about PHP <code>pow()<\/code> Function<\/h3>\n<ol>\n<li>\n<p> In PHP 5.6 onwards, you may prefer to use the ** operator. <\/p>\n<\/li>\n<li>\n<p> This function will convert all input to a number, even non-scalar values, which could lead to <strong>weird<\/strong> results. <\/p>\n<\/li>\n<\/ol>\n<h3>Additional Tips from Fellow Developers<\/h3>\n<p>Contributed By: chris<\/p>\n<pre><code>Many notations use \"^\" as a power operator, but in PHP (and other C-based languages) that is actually the XOR operator. You need to use this 'pow' function, there is no power operator.\ni.e. 3^2 means \"3 XOR 2\" not \"3 squared\".\nIt is particular confusing as when doing Pythagoras theorem in a 'closet points' algorithm using \"^\" you get results that look vaguely correct but with an error.<\/pre>\n<p><\/code><\/p>\n<p>Contributed By: gilthans<\/p>\n<pre><code>Note that pow(0, 0) equals to 1 although mathematically this is undefined.<\/pre>\n<p><\/code><\/p>\n<h2 id=\"sqrt\">PHP <code>sqrt()<\/code> Function<\/h2>\n<h3>PHP <code>sqrt()<\/code> Usage<\/h3>\n<p>The PHP <code><code>sqrt()<\/code><\/code> function will give you the square root of <code class=\"parameter\">arg<\/code>.<\/p>\n<h3>PHP <code>sqrt()<\/code> Syntax<\/h3>\n<pre><code class=\"lang-php\"> sqrt ( float $arg ) : float<\/code><\/pre>\n<h3>PHP <code>sqrt()<\/code> Parameters<\/h3>\n<ol>\n<li>\n<p><code>arg<\/code> \u2014 The argument to process <\/p>\n<\/li>\n<\/ol>\n<h3>PHP <code>sqrt()<\/code> Return Value<\/h3>\n<p>The PHP <code>sqrt()<\/code> function returns the square root of <code class=\"parameter\">arg<\/code> or the special value <strong>NAN<\/strong> for negative numbers.<\/p>\n<h3>PHP <code>sqrt()<\/code> Working Examples<\/h3>\n<h4>1. sqrt() example<\/h4>\n<pre><code class=\"lang-php\">&lt;?php\n\/\/ Precision depends on your precision directive\necho sqrt(9); \/\/ 3\necho sqrt(10); \/\/ 3.16227766 ...\n?&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Random Number Functions Functions in PHP Function Name Function Description exp() Calculates the exponent of e expm1() Returns exp(number) &#8211; 1, computed in a way that is accurate even when the value of number is close to zero log10() Base-10 logarithm log1p() Returns log(1 + number), computed in a way that is accurate even when [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[8,5],"class_list":["post-59","post","type-post","status-publish","format-standard","hentry","category-reference","tag-math","tag-php"],"_links":{"self":[{"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/posts\/59","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":0,"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"wp:attachment":[{"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hellonitish.com\/blog\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}