PHP 5 Math 函数
<div id="article_content" class="article_content clearfix"><link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
<link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-6e43165c0a.css">
<div id="content_views" class="htmledit_views">
<h2>PHP Math 简介</h2>
<p>Math 函数能处理 integer 和 float 范围内的值。</p>
<hr>
<h2>安装</h2>
<p>PHP Math 函数是 PHP 核心的组成部分。无需安装即可使用这些函数。</p>
<hr>
<h2>PHP 5 Math 函数</h2>
<table><tbody><tr><th>函数</th><th>描述</th></tr><tr><td><ahref="https://www.runoob.com/php/func-math-abs.html">abs()</a></td><td>返回一个数的绝对值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-acos.html">acos()</a></td><td>返回一个数的反余弦。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-acosh.html">acosh()</a></td><td>返回一个数的反双曲余弦。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-asin.html">asin()</a></td><td>返回一个数的反正弦。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-asinh.html">asinh()</a></td><td>返回一个数的反双曲正弦。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-atan.html">atan()</a></td><td>返回一个数的反正切。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-atan2.html">atan2()</a></td><td>返回两个变量 x 和 y 的反正切。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-atanh.html">atanh()</a></td><td>返回一个数的反双曲正切。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-base-convert.html">base_convert()</a></td><td>在任意进制之间转换数字。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-bindec.html">bindec()</a></td><td>把二进制数转换为十进制数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-ceil.html">ceil()</a></td><td>向上舍入为最接近的整数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-cos.html">cos()</a></td><td>返回一个数的余弦。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-cosh.html">cosh()</a></td><td>返回一个数的双曲余弦。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-decbin.html">decbin()</a></td><td>把十进制数转换为二进制数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-dechex.html">dechex()</a></td><td>把十进制数转换为十六进制数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-decoct.html">decoct()</a></td><td>把十进制数转换为八进制数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-deg2rad.html">deg2rad()</a></td><td>将角度值转换为弧度值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-exp.html">exp()</a></td><td>返回 Ex 的值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-expm1.html">expm1()</a></td><td>返回 Ex - 1 的值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-floor.html">floor()</a></td><td>向下舍入为最接近的整数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-fmod.html">fmod()</a></td><td>返回 x/y 的浮点数余数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-getrandmax.html">getrandmax()</a></td><td>返回通过调用 rand() 函数显示的随机数的最大可能值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-hexdec.html">hexdec()</a></td><td>把十六进制数转换为十进制数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-hypot.html">hypot()</a></td><td>计算直角三角形的斜边长度。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-is-finite.html">is_finite()</a></td><td>判断是否为有限值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-is-infinite.html">is_infinite()</a></td><td>判断是否为无限值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-is-nan.html">is_nan()</a></td><td>判断是否为非数值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-lcg-value.html">lcg_value()</a></td><td>返回范围为 (0, 1) 的一个伪随机数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-log.html">log()</a></td><td>返回一个数的自然对数(以 E 为底)。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-log10.html">log10()</a></td><td>返回一个数的以 10 为底的对数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-log1p.html">log1p()</a></td><td>返回 log(1+number)</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-max.html">max()</a></td><td>返回一个数组中的最大值,或者几个指定值中的最大值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-min.html">min()</a></td><td>返回一个数组中的最小值,或者几个指定值中的最小值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-mt-getrandmax.html">mt_getrandmax()</a></td><td>返回通过调用 mt_rand() 函数显示的随机数的最大可能值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-mt-rand.html">mt_rand()</a></td><td>使用 Mersenne Twister 算法生成随机整数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-mt-srand.html">mt_srand()</a></td><td>播种 Mersenne Twister 随机数生成器。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-octdec.html">octdec()</a></td><td>把八进制数转换为十进制数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-pi.html">pi()</a></td><td>返回圆周率 PI 的值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-pow.html">pow()</a></td><td>返回 x 的 y 次方。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-rad2deg.html">rad2deg()</a></td><td>把弧度值转换为角度值。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-rand.html">rand()</a></td><td>返回随机整数。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-round.html">round()</a></td><td>对浮点数进行四舍五入。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-sin.html">sin()</a></td><td>返回一个数的正弦。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-sinh.html">sinh()</a></td><td>返回一个数的双曲正弦。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-sqrt.html">sqrt()</a></td><td>返回一个数的平方根。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-srand.html">srand()</a></td><td>播种随机数生成器。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-tan.html">tan()</a></td><td>返回一个数的正切。</td></tr><tr><td><ahref="https://www.runoob.com/php/func-math-tanh.html">tanh()</a></td><td>返回一个数的双曲正切。</td></tr></tbody></table>
<p></p>
<hr>
<h2>PHP 5 预定义的 Math 常量</h2>
<table><tbody><tr><th>常量</th><th>值</th><th>描述</th><th>PHP 版本</th></tr><tr><td>INF</td><td>INF</td><td>无限</td><td>PHP 4</td></tr><tr><td>M_E</td><td>2.7182818284590452354</td><td>返回 e</td><td>PHP 4</td></tr><tr><td>M_EULER</td><td>0.57721566490153286061</td><td>返回 Euler 常量</td><td>PHP 4</td></tr><tr><td>M_LNPI</td><td>1.14472988584940017414</td><td>返回圆周率 PI 的自然对数:log_e(pi)</td><td>PHP 5.2</td></tr><tr><td>M_LN2</td><td>0.69314718055994530942</td><td>返回 2 的自然对数:log_e 2</td><td>PHP 4</td></tr><tr><td>M_LN10</td><td>2.30258509299404568402</td><td>返回 10 的自然对数:log_e 10</td><td>PHP 4</td></tr><tr><td>M_LOG2E</td><td>1.4426950408889634074</td><td>返回 E 的以 2 为底的对数:log_2 e</td><td>PHP 4</td></tr><tr><td>M_LOG10E</td><td>0.43429448190325182765</td><td>返回 E 的以 10 为底的对数:log_10 e</td><td>PHP 4</td></tr><tr><td>M_PI</td><td>3.14159265358979323846</td><td>返回 Pi</td><td>PHP 4</td></tr><tr><td>M_PI_2</td><td>1.57079632679489661923</td><td>返回 Pi/2</td><td>PHP 4</td></tr><tr><td>M_PI_4</td><td>0.78539816339744830962</td><td>返回 Pi/4</td><td>PHP 4</td></tr><tr><td>M_1_PI</td><td>0.31830988618379067154</td><td>返回 1/Pi</td><td>PHP 4</td></tr><tr><td>M_2_PI</td><td>0.63661977236758134308</td><td>返回 2/Pi</td><td>PHP 4</td></tr><tr><td>M_SQRTPI</td><td>1.77245385090551602729</td><td>返回圆周率 PI 的平方根:sqrt(pi)</td><td>PHP 5.2</td></tr><tr><td>M_2_SQRTPI</td><td>1.12837916709551257390</td><td>返回圆周率 PI 的 2/平方根:2/sqrt(pi)</td><td>PHP 4</td></tr><tr><td>M_SQRT1_2</td><td>0.70710678118654752440</td><td>返回 1/2 的平方根:1/sqrt(2)</td><td>PHP 4</td></tr><tr><td>M_SQRT2</td><td>1.41421356237309504880</td><td>返回 2 的平方根:sqrt(2)</td><td>PHP 4</td></tr><tr><td>M_SQRT3</td><td>1.73205080756887729352</td><td>返回 3 的平方根:sqrt(3)</td><td>PHP 5.2</td></tr><tr><td>NAN</td><td>NAN</td><td>不是一个数字</td><td>PHP 4</td></tr><tr><td>PHP_ROUND_HALF_UP</td><td>1</td><td>遇到 .5 的情况时向上舍入</td><td>PHP 5.3</td></tr><tr><td>PHP_ROUND_HALF_DOWN</td><td>2</td><td>遇到 .5 的情况时向下舍入</td><td>PHP 5.3</td></tr><tr><td>PHP_ROUND_HALF_EVEN</td><td>3</td><td>遇到 .5 的情况时取偶数舍入</td><td>PHP 5.3</td></tr><tr><td>PHP_ROUND_HALF_ODD</td><td>4</td><td>遇到 .5 的情况时取奇数舍入</td><td>PHP 5.3</td></tr></tbody></table>
</div>
</div>
<div id="treeSkill"></div>
页:
[1]