Examples of common PHP mathematical functions and BC high-precision mathematical functions, high-precision mathematical functions

Source: Internet
Author: User
Tags binary to decimal decimal to binary sin cos

Examples of common PHP mathematical functions and BC high-precision mathematical functions, high-precision mathematical functions

This article provides examples of common PHP mathematical functions and BC high-precision mathematical functions. We will share this with you for your reference. The details are as follows:

1. Addition of any bcadd precision
2. subtraction of any bcsub precision
3. bcmul multiplication and bcdiv Division
4. bcmod returns the remainder. (More powerful than %)
5. bcpow power function operation
6. square root of bcsqrt
7. sqrt square root operation
7. pow power
8. abs calculates the absolute value.
9. pi obtains the circumference rate value

Trigonometric function

Sin cos tan asin acos atan (expressed in radians)
Deg 2rad angle to radian
Rad2deg radians to degrees

Index

Evaluate the natural logarithm of log, and evaluate the base-10 logarithm of log10
Exp base on e Power

Various Numeric conversions

Base_convert universal arbitrary number Conversion
Bindec binary to decimal
Decbin decimal to binary
Dechex decimal to hexadecimal
Decoct decimal to octal
Convert hexdec hexadecimal to decimal
Octdec octal to decimal

Examples of BC high-precision functions:

<? Php /************************************** **************************************** * ******** php BC high-precision function library * php bc math includes: add, compare, divide, subtract, remainder, multiply, n, configure the default number of decimal places, square * these functions are useful when it comes to money-related computing ************************** **************************************** * ******************** there is a situation in the work of comparing two high-precision numbers, 0.00! = 0 * int bccomp (string $ left_operand, string $ right_operand [, int $ scale]) * $ left = $ right returns 0 * $ left <$ right returns-1 * $ left> $ right returns 1 * $ scale decimal place ********** **************************************** * **********************************/$ = 4.45; $ B = 5.54; if (bccomp ($ a, $ B, 2) = 0) {echo "completely equal ";} /*************************************** **************************************** * ******** add two high-precision numbers * String bcadd (string $ left_operand, string $ right_operand [, int $ scale]) * $ scale returns the number of decimal places ********************************** **************************************** * ************/$ a = 1.0321456; $ B = 0.0123456; $ c = bcadd ($ a, $ B, 2); var_dump ($ c ); /*************************************** **************************************** * ******* subtraction of two high-precision numbers * sstring bcsub (string $ left_operand, string $ righ T_operand [, int $ scale]) * $ scale returns the number of decimal places ********************************** **************************************** * ************/$ a = 1.0321456; $ B = 3.0123456; $ c = bcsub ($ a, $ B, 2); var_dump ($ c ); /*************************************** * ***************** remainder/modulo of two high-precision computations * string bcmod (string $ left_operand, string $ modulus) **************************************** * **************/$ a = 6; $ B = 4; $ c = Bcmod ($ a, $ B); var_dump ($ c ); /*************************************** **************************************** * ******* division of two high-precision numbers * string bcdiv (string $ left_operand, string $ right_operand [, int $ scale]) * $ scale indicates the number of decimal places. The default value is 0 ******************************** **************************************** * **************/$ a = 6; $ B = 5; $ c = bcdiv ($ a, $ B, 3); var_dump ($ c ); /********************************** **************************************** * ************* Multiply two high-precision numbers * string bcmul (string $ left_operand, string $ right_operand [, int $ scale]) * $ scale indicates the number of decimal places. The default value is 0 ******************************** **************************************** * *************/$ a = 3.1415926; $ B = 2.4569874566; $ c = bcmul ($ a, $ B, 6); var_dump ($ c ); /*************************************** **************************************** *** * ***** The power of two high-precision numbers * string bcpow (string $ left_operand, string $ right_operand [, int $ scale]) * $ scale indicates the number of decimal places. The default value is 0 ******************************** **************************************** * *************/$ a = 3.1415926; $ B = 2; $ c = bcpow ($ a, $ B, 3); var_dump ($ c ); /*************************************** * ********** calculate the square root of a precise number * string bcsqrt (string $ operand [, int $ scale]) * $ scale the number of decimal places is 0 by default ******** **************************************** * **/$ B = bcsqrt ($, 6); var_dump ($ B ); /****************************** set the decimal point of the bc function * bool bcscale (int $ scale) * $ scale the number of decimal places is 0 * (2);?>

Running result:

string(4) "1.04"string(5) "-1.98"string(1) "2"string(5) "1.200"string(8) "7.718853"string(5) "9.869"string(8) "1.772453"

PS: Here are some recommended computing tools for your reference:

Calculation tool for online mona1 functions (equations:
Http://tools.jb51.net/jisuanqi/equ_jisuanqi

Scientific calculator online use _ advanced calculator online computing:
Http://tools.jb51.net/jisuanqi/jsqkexue

Online calculator _ standard calculator:
Http://tools.jb51.net/jisuanqi/jsq

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.