Back to index

php5  5.3.10
Defines | Functions
php_math.h File Reference
#include <math.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define M_E   2.7182818284590452354 /* e */
#define M_LOG2E   1.4426950408889634074 /* log_2 e */
#define M_LOG10E   0.43429448190325182765 /* log_10 e */
#define M_LN2   0.69314718055994530942 /* log_e 2 */
#define M_LN10   2.30258509299404568402 /* log_e 10 */
#define M_PI   3.14159265358979323846 /* pi */
#define M_PI_2   1.57079632679489661923 /* pi/2 */
#define M_PI_4   0.78539816339744830962 /* pi/4 */
#define M_1_PI   0.31830988618379067154 /* 1/pi */
#define M_2_PI   0.63661977236758134308 /* 2/pi */
#define M_SQRTPI   1.77245385090551602729 /* sqrt(pi) */
#define M_2_SQRTPI   1.12837916709551257390 /* 2/sqrt(pi) */
#define M_LNPI   1.14472988584940017414 /* ln(pi) */
#define M_EULER   0.57721566490153286061 /* Euler constant */
#define M_SQRT2   1.41421356237309504880 /* sqrt(2) */
#define M_SQRT1_2   0.70710678118654752440 /* 1/sqrt(2) */
#define M_SQRT3   1.73205080756887729352 /* sqrt(3) */
#define PHP_ROUND_HALF_UP   0x01 /* Arithmetic rounding, up == away from zero */
#define PHP_ROUND_HALF_DOWN   0x02 /* Down == towards zero */
#define PHP_ROUND_HALF_EVEN   0x03 /* Banker's rounding */
#define PHP_ROUND_HALF_ODD   0x04

Functions

PHPAPI char * _php_math_number_format (double, int, char, char)
PHPAPI char * _php_math_longtobase (zval *arg, int base)
PHPAPI long _php_math_basetolong (zval *arg, int base)
PHPAPI int _php_math_basetozval (zval *arg, int base, zval *ret)
PHPAPI char * _php_math_zvaltobase (zval *arg, int base TSRMLS_DC)
 PHP_FUNCTION (sin)
 PHP_FUNCTION (cos)
 PHP_FUNCTION (tan)
 PHP_FUNCTION (asin)
 PHP_FUNCTION (acos)
 PHP_FUNCTION (atan)
 PHP_FUNCTION (atan2)
 PHP_FUNCTION (pi)
 PHP_FUNCTION (exp)
 PHP_FUNCTION (log)
 PHP_FUNCTION (log10)
 PHP_FUNCTION (is_finite)
 PHP_FUNCTION (is_infinite)
 PHP_FUNCTION (is_nan)
 PHP_FUNCTION (pow)
 PHP_FUNCTION (sqrt)
 PHP_FUNCTION (srand)
 PHP_FUNCTION (rand)
 PHP_FUNCTION (getrandmax)
 PHP_FUNCTION (mt_srand)
 PHP_FUNCTION (mt_rand)
 PHP_FUNCTION (mt_getrandmax)
 PHP_FUNCTION (abs)
 PHP_FUNCTION (ceil)
 PHP_FUNCTION (floor)
 PHP_FUNCTION (round)
 PHP_FUNCTION (decbin)
 PHP_FUNCTION (dechex)
 PHP_FUNCTION (decoct)
 PHP_FUNCTION (bindec)
 PHP_FUNCTION (hexdec)
 PHP_FUNCTION (octdec)
 PHP_FUNCTION (base_convert)
 PHP_FUNCTION (number_format)
 PHP_FUNCTION (fmod)
 PHP_FUNCTION (deg2rad)
 PHP_FUNCTION (rad2deg)
 PHP_FUNCTION (hypot)
 PHP_FUNCTION (expm1)
 PHP_FUNCTION (log1p)
 PHP_FUNCTION (sinh)
 PHP_FUNCTION (cosh)
 PHP_FUNCTION (tanh)
 PHP_FUNCTION (asinh)
 PHP_FUNCTION (acosh)
 PHP_FUNCTION (atanh)

Define Documentation

#define M_1_PI   0.31830988618379067154 /* 1/pi */

Definition at line 120 of file php_math.h.

#define M_2_PI   0.63661977236758134308 /* 2/pi */

Definition at line 124 of file php_math.h.

#define M_2_SQRTPI   1.12837916709551257390 /* 2/sqrt(pi) */

Definition at line 132 of file php_math.h.

#define M_E   2.7182818284590452354 /* e */

Definition at line 88 of file php_math.h.

#define M_EULER   0.57721566490153286061 /* Euler constant */

Definition at line 140 of file php_math.h.

#define M_LN10   2.30258509299404568402 /* log_e 10 */

Definition at line 104 of file php_math.h.

#define M_LN2   0.69314718055994530942 /* log_e 2 */

Definition at line 100 of file php_math.h.

#define M_LNPI   1.14472988584940017414 /* ln(pi) */

Definition at line 136 of file php_math.h.

#define M_LOG10E   0.43429448190325182765 /* log_10 e */

Definition at line 96 of file php_math.h.

#define M_LOG2E   1.4426950408889634074 /* log_2 e */

Definition at line 92 of file php_math.h.

#define M_PI   3.14159265358979323846 /* pi */

Definition at line 108 of file php_math.h.

#define M_PI_2   1.57079632679489661923 /* pi/2 */

Definition at line 112 of file php_math.h.

#define M_PI_4   0.78539816339744830962 /* pi/4 */

Definition at line 116 of file php_math.h.

#define M_SQRT1_2   0.70710678118654752440 /* 1/sqrt(2) */

Definition at line 148 of file php_math.h.

#define M_SQRT2   1.41421356237309504880 /* sqrt(2) */

Definition at line 144 of file php_math.h.

#define M_SQRT3   1.73205080756887729352 /* sqrt(3) */

Definition at line 152 of file php_math.h.

#define M_SQRTPI   1.77245385090551602729 /* sqrt(pi) */

Definition at line 128 of file php_math.h.

#define PHP_ROUND_HALF_DOWN   0x02 /* Down == towards zero */

Definition at line 161 of file php_math.h.

#define PHP_ROUND_HALF_EVEN   0x03 /* Banker's rounding */

Definition at line 165 of file php_math.h.

#define PHP_ROUND_HALF_ODD   0x04

Definition at line 169 of file php_math.h.

#define PHP_ROUND_HALF_UP   0x01 /* Arithmetic rounding, up == away from zero */

Definition at line 157 of file php_math.h.


Function Documentation

PHPAPI long _php_math_basetolong ( zval *  arg,
int  base 
)

Definition at line 794 of file math.c.

{
       long num = 0, digit, onum;
       int i;
       char c, *s;

       if (Z_TYPE_P(arg) != IS_STRING || base < 2 || base > 36) {
              return 0;
       }

       s = Z_STRVAL_P(arg);

       for (i = Z_STRLEN_P(arg); i > 0; i--) {
              c = *s++;
              
              digit = (c >= '0' && c <= '9') ? c - '0'
                     : (c >= 'A' && c <= 'Z') ? c - 'A' + 10
                     : (c >= 'a' && c <= 'z') ? c - 'a' + 10
                     : base;
              
              if (digit >= base) {
                     continue;
              }

              onum = num;
              num = num * base + digit;
              if (num > onum)
                     continue;

              {
                     TSRMLS_FETCH();

                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number '%s' is too big to fit in long", s);
                     return LONG_MAX;
              }
       }

       return num;
}
PHPAPI int _php_math_basetozval ( zval *  arg,
int  base,
zval *  ret 
)

Definition at line 839 of file math.c.

{
       long num = 0;
       double fnum = 0;
       int i;
       int mode = 0;
       char c, *s;
       long cutoff;
       int cutlim;

       if (Z_TYPE_P(arg) != IS_STRING || base < 2 || base > 36) {
              return FAILURE;
       }

       s = Z_STRVAL_P(arg);

       cutoff = LONG_MAX / base;
       cutlim = LONG_MAX % base;
       
       for (i = Z_STRLEN_P(arg); i > 0; i--) {
              c = *s++;

              /* might not work for EBCDIC */
              if (c >= '0' && c <= '9') 
                     c -= '0';
              else if (c >= 'A' && c <= 'Z') 
                     c -= 'A' - 10;
              else if (c >= 'a' && c <= 'z') 
                     c -= 'a' - 10;
              else
                     continue;

              if (c >= base)
                     continue;
              
              switch (mode) {
              case 0: /* Integer */
                     if (num < cutoff || (num == cutoff && c <= cutlim)) {
                            num = num * base + c;
                            break;
                     } else {
                            fnum = num;
                            mode = 1;
                     }
                     /* fall-through */
              case 1: /* Float */
                     fnum = fnum * base + c;
              }      
       }

       if (mode == 1) {
              ZVAL_DOUBLE(ret, fnum);
       } else {
              ZVAL_LONG(ret, num);
       }
       return SUCCESS;
}

Here is the caller graph for this function:

PHPAPI char* _php_math_longtobase ( zval *  arg,
int  base 
)

Definition at line 903 of file math.c.

{
       static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
       char buf[(sizeof(unsigned long) << 3) + 1];
       char *ptr, *end;
       unsigned long value;

       if (Z_TYPE_P(arg) != IS_LONG || base < 2 || base > 36) {
              return STR_EMPTY_ALLOC();
       }

       value = Z_LVAL_P(arg);

       end = ptr = buf + sizeof(buf) - 1;
       *ptr = '\0';

       do {
              *--ptr = digits[value % base];
              value /= base;
       } while (ptr > buf && value);

       return estrndup(ptr, end - ptr);
}

Here is the caller graph for this function:

PHPAPI char* _php_math_number_format ( double  ,
int  ,
char  ,
char   
)

Definition at line 1095 of file math.c.

{
       char *tmpbuf = NULL, *resbuf;
       char *s, *t;  /* source, target */
       char *dp;
       int integral;
       int tmplen, reslen=0;
       int count=0;
       int is_negative=0;

       if (d < 0) {
              is_negative = 1;
              d = -d;
       }

       dec = MAX(0, dec);
       d = _php_math_round(d, dec, PHP_ROUND_HALF_UP);

       tmplen = spprintf(&tmpbuf, 0, "%.*F", dec, d);

       if (tmpbuf == NULL || !isdigit((int)tmpbuf[0])) {
              return tmpbuf;
       }

       /* find decimal point, if expected */
       if (dec) {
              dp = strpbrk(tmpbuf, ".,");
       } else {
              dp = NULL;
       }

       /* calculate the length of the return buffer */
       if (dp) {
              integral = dp - tmpbuf;
       } else {
              /* no decimal point was found */
              integral = tmplen;
       }

       /* allow for thousand separators */
       if (thousand_sep) {
              integral += (integral-1) / 3;
       }
       
       reslen = integral;
       
       if (dec) {
              reslen += dec;

              if (dec_point) {
                     reslen++;
              }
       }

       /* add a byte for minus sign */
       if (is_negative) {
              reslen++;
       }
       resbuf = (char *) emalloc(reslen+1); /* +1 for NUL terminator */

       s = tmpbuf+tmplen-1;
       t = resbuf+reslen;
       *t-- = '\0';

       /* copy the decimal places.
        * Take care, as the sprintf implementation may return less places than
        * we requested due to internal buffer limitations */
       if (dec) {
              int declen = dp ? s - dp : 0;
              int topad = dec > declen ? dec - declen : 0;

              /* pad with '0's */
              while (topad--) {
                     *t-- = '0';
              }
              
              if (dp) {
                     s -= declen + 1; /* +1 to skip the point */
                     t -= declen;

                     /* now copy the chars after the point */
                     memcpy(t + 1, dp + 1, declen);
              }

              /* add decimal point */
              if (dec_point) {
                     *t-- = dec_point;
              }
       }

       /* copy the numbers before the decimal point, adding thousand
        * separator every three digits */
       while(s >= tmpbuf) {
              *t-- = *s--;
              if (thousand_sep && (++count%3)==0 && s>=tmpbuf) {
                     *t-- = thousand_sep;
              }
       }

       /* and a minus sign, if needed */
       if (is_negative) {
              *t-- = '-';
       }

       efree(tmpbuf);
       
       return resbuf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI char* _php_math_zvaltobase ( zval *  arg,
int base  TSRMLS_DC 
)

Definition at line 933 of file math.c.

{
       static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";

       if ((Z_TYPE_P(arg) != IS_LONG && Z_TYPE_P(arg) != IS_DOUBLE) || base < 2 || base > 36) {
              return STR_EMPTY_ALLOC();
       }

       if (Z_TYPE_P(arg) == IS_DOUBLE) {
              double fvalue = floor(Z_DVAL_P(arg)); /* floor it just in case */
              char *ptr, *end;
              char buf[(sizeof(double) << 3) + 1];

              /* Don't try to convert +/- infinity */
              if (fvalue == HUGE_VAL || fvalue == -HUGE_VAL) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number too large");
                     return STR_EMPTY_ALLOC();
              }

              end = ptr = buf + sizeof(buf) - 1;
              *ptr = '\0';

              do {
                     *--ptr = digits[(int) fmod(fvalue, base)];
                     fvalue /= base;
              } while (ptr > buf && fabs(fvalue) >= 1);

              return estrndup(ptr, end - ptr);
       }
       
       return _php_math_longtobase(arg, base);
}      

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_FUNCTION ( sin  )

Definition at line 383 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(sin(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( cos  )

Definition at line 396 of file math.c.

{
       double num;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(cos(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( tan  )

Definition at line 409 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(tan(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( asin  )

Definition at line 422 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(asin(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( acos  )

Definition at line 435 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(acos(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( atan  )

Definition at line 448 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(atan(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( atan2  )

Definition at line 461 of file math.c.

{
       double num1, num2;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd", &num1, &num2) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(atan2(num1, num2));
}

Here is the call graph for this function:

PHP_FUNCTION ( pi  )

Definition at line 552 of file math.c.

PHP_FUNCTION ( exp  )

Definition at line 649 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }

       RETURN_DOUBLE(exp(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( log  )

Definition at line 697 of file math.c.

{
       double num, base = 0;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|d", &num, &base) == FAILURE) {
              return;
       }
       if (ZEND_NUM_ARGS() == 1) {
              RETURN_DOUBLE(log(num));
       }
       if (base <= 0.0) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "base must be greater than 0");                       
              RETURN_FALSE;
       }
       if (base == 1) {
              RETURN_DOUBLE(php_get_nan());
       } else {
              RETURN_DOUBLE(log(num) / log(base));
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( log10  )

Definition at line 721 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(log10(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( is_finite  )

Definition at line 560 of file math.c.

{
       double dval;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &dval) == FAILURE) {
              return;
       }
       RETURN_BOOL(zend_finite(dval));
}

Here is the call graph for this function:

PHP_FUNCTION ( is_infinite  )

Definition at line 573 of file math.c.

{
       double dval;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &dval) == FAILURE) {
              return;
       }
       RETURN_BOOL(zend_isinf(dval));
}

Here is the call graph for this function:

PHP_FUNCTION ( is_nan  )

Definition at line 586 of file math.c.

{
       double dval;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &dval) == FAILURE) {
              return;
       }
       RETURN_BOOL(zend_isnan(dval));
}

Here is the call graph for this function:

PHP_FUNCTION ( pow  )

Definition at line 599 of file math.c.

{
       zval *zbase, *zexp;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/z/", &zbase, &zexp) == FAILURE) {
              return;
       }

       /* make sure we're dealing with numbers */
       convert_scalar_to_number(zbase TSRMLS_CC);
       convert_scalar_to_number(zexp TSRMLS_CC);

       /* if both base and exponent were longs, we'll try to get a long out */
       if (Z_TYPE_P(zbase) == IS_LONG && Z_TYPE_P(zexp) == IS_LONG && Z_LVAL_P(zexp) >= 0) {
              long l1 = 1, l2 = Z_LVAL_P(zbase), i = Z_LVAL_P(zexp);
              
              if (i == 0) {
                     RETURN_LONG(1L);
              } else if (l2 == 0) {
                     RETURN_LONG(0);
              }

              /* calculate pow(long,long) in O(log exp) operations, bail if overflow */
              while (i >= 1) {
                     int overflow;
                     double dval = 0.0;

                     if (i % 2) {
                            --i;
                            ZEND_SIGNED_MULTIPLY_LONG(l1,l2,l1,dval,overflow);
                            if (overflow) RETURN_DOUBLE(dval * pow(l2,i));
                     } else {
                            i /= 2;
                            ZEND_SIGNED_MULTIPLY_LONG(l2,l2,l2,dval,overflow);
                            if (overflow) RETURN_DOUBLE((double)l1 * pow(dval,i));
                     }
                     if (i == 0) {
                            RETURN_LONG(l1);
                     }
              }
       }
       convert_to_double(zbase);
       convert_to_double(zexp);
       
       RETURN_DOUBLE(pow(Z_DVAL_P(zbase), Z_DVAL_P(zexp)));
}

Here is the call graph for this function:

PHP_FUNCTION ( sqrt  )

Definition at line 734 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(sqrt(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( srand  )

Definition at line 231 of file rand.c.

{
       long seed = 0;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &seed) == FAILURE)
              return;

       if (ZEND_NUM_ARGS() == 0)
              seed = GENERATE_SEED();

       php_srand(seed TSRMLS_CC);
}

Here is the call graph for this function:

PHP_FUNCTION ( rand  )

Definition at line 290 of file rand.c.

{
       long min;
       long max;
       long number;
       int  argc = ZEND_NUM_ARGS();

       if (argc != 0 && zend_parse_parameters(argc TSRMLS_CC, "ll", &min, &max) == FAILURE)
              return;

       number = php_rand(TSRMLS_C);
       if (argc == 2) {
              RAND_RANGE(number, min, max, PHP_RAND_MAX);
       }

       RETURN_LONG(number);
}

Here is the call graph for this function:

PHP_FUNCTION ( getrandmax  )

Definition at line 350 of file rand.c.

PHP_FUNCTION ( mt_srand  )

Definition at line 247 of file rand.c.

{
       long seed = 0;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &seed) == FAILURE) 
              return;

       if (ZEND_NUM_ARGS() == 0)
              seed = GENERATE_SEED();

       php_mt_srand(seed TSRMLS_CC);
}

Here is the call graph for this function:

PHP_FUNCTION ( mt_rand  )

Definition at line 311 of file rand.c.

{
       long min;
       long max;
       long number;
       int  argc = ZEND_NUM_ARGS();

       if (argc != 0) {
              if (zend_parse_parameters(argc TSRMLS_CC, "ll", &min, &max) == FAILURE) {
                     return;
              } else if (max < min) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "max(%ld) is smaller than min(%ld)", max, min);
                     RETURN_FALSE;
              }
       }

       if (!BG(mt_rand_is_seeded)) {
              php_mt_srand(GENERATE_SEED() TSRMLS_CC);
       }

       /*
        * Melo: hmms.. randomMT() returns 32 random bits...
        * Yet, the previous php_rand only returns 31 at most.
        * So I put a right shift to loose the lsb. It *seems*
        * better than clearing the msb. 
        * Update: 
        * I talked with Cokus via email and it won't ruin the algorithm
        */
       number = (long) (php_mt_rand(TSRMLS_C) >> 1);
       if (argc == 2) {
              RAND_RANGE(number, min, max, PHP_MT_RAND_MAX);
       }

       RETURN_LONG(number);
}

Here is the call graph for this function:

PHP_FUNCTION ( mt_getrandmax  )

Definition at line 362 of file rand.c.

{
       if (zend_parse_parameters_none() == FAILURE) {
              return;
       }

       /*
        * Melo: it could be 2^^32 but we only use 2^^31 to maintain
        * compatibility with the previous php_rand
        */
       RETURN_LONG(PHP_MT_RAND_MAX); /* 2^^31 */
}
PHP_FUNCTION ( abs  )

Definition at line 277 of file math.c.

{
       zval **value;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &value) == FAILURE) {
              return;
       }
       convert_scalar_to_number_ex(value);
       
       if (Z_TYPE_PP(value) == IS_DOUBLE) {
              RETURN_DOUBLE(fabs(Z_DVAL_PP(value)));
       } else if (Z_TYPE_PP(value) == IS_LONG) {
              if (Z_LVAL_PP(value) == LONG_MIN) {
                     RETURN_DOUBLE(-(double)LONG_MIN);
              } else {
                     RETURN_LONG(Z_LVAL_PP(value) < 0 ? -Z_LVAL_PP(value) : Z_LVAL_PP(value));
              }
       }
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( ceil  )

Definition at line 301 of file math.c.

{
       zval **value;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &value) == FAILURE) {
              return;
       }
       convert_scalar_to_number_ex(value);

       if (Z_TYPE_PP(value) == IS_DOUBLE) {
              RETURN_DOUBLE(ceil(Z_DVAL_PP(value)));
       } else if (Z_TYPE_PP(value) == IS_LONG) {
              convert_to_double_ex(value);
              RETURN_DOUBLE(Z_DVAL_PP(value));
       }
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( floor  )

Definition at line 322 of file math.c.

{
       zval **value;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &value) == FAILURE) {
              return;
       }
       convert_scalar_to_number_ex(value);

       if (Z_TYPE_PP(value) == IS_DOUBLE) {
              RETURN_DOUBLE(floor(Z_DVAL_PP(value)));
       } else if (Z_TYPE_PP(value) == IS_LONG) {
              convert_to_double_ex(value);
              RETURN_DOUBLE(Z_DVAL_PP(value));
       }
       RETURN_FALSE;
}

Here is the call graph for this function:

Definition at line 343 of file math.c.

{
       zval **value;
       int places = 0;
       long precision = 0;
       long mode = PHP_ROUND_HALF_UP;
       double return_val;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|ll", &value, &precision, &mode) == FAILURE) {
              return;
       }

       if (ZEND_NUM_ARGS() >= 2) {
              places = (int) precision;
       }
       convert_scalar_to_number_ex(value);

       switch (Z_TYPE_PP(value)) {
              case IS_LONG:
                     /* Simple case - long that doesn't need to be rounded. */
                     if (places >= 0) {
                            RETURN_DOUBLE((double) Z_LVAL_PP(value));
                     }
                     /* break omitted intentionally */

              case IS_DOUBLE:
                     return_val = (Z_TYPE_PP(value) == IS_LONG) ? (double)Z_LVAL_PP(value) : Z_DVAL_PP(value);
                     return_val = _php_math_round(return_val, places, mode);
                     RETURN_DOUBLE(return_val);
                     break;

              default:
                     RETURN_FALSE;
                     break;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( decbin  )

Definition at line 1017 of file math.c.

{
       zval **arg;
       char *result;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
              return;
       }
       convert_to_long_ex(arg);
       result = _php_math_longtobase(*arg, 2);
       RETURN_STRING(result, 0);
}

Here is the call graph for this function:

PHP_FUNCTION ( dechex  )

Definition at line 1049 of file math.c.

{
       zval **arg;
       char *result;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
              return;
       }
       convert_to_long_ex(arg);
       result = _php_math_longtobase(*arg, 16);
       RETURN_STRING(result, 0);
}

Here is the call graph for this function:

PHP_FUNCTION ( decoct  )

Definition at line 1033 of file math.c.

{
       zval **arg;
       char *result;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
              return;
       }
       convert_to_long_ex(arg);
       result = _php_math_longtobase(*arg, 8);
       RETURN_STRING(result, 0);
}

Here is the call graph for this function:

PHP_FUNCTION ( bindec  )

Definition at line 969 of file math.c.

{
       zval **arg;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
              return;
       }
       convert_to_string_ex(arg);
       if (_php_math_basetozval(*arg, 2, return_value) == FAILURE) {
              RETURN_FALSE;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( hexdec  )

Definition at line 985 of file math.c.

{
       zval **arg;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
              return;
       }
       convert_to_string_ex(arg);
       if (_php_math_basetozval(*arg, 16, return_value) == FAILURE) {
              RETURN_FALSE;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( octdec  )

Definition at line 1001 of file math.c.

{
       zval **arg;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
              return;
       }
       convert_to_string_ex(arg);
       if (_php_math_basetozval(*arg, 8, return_value) == FAILURE) {
              RETURN_FALSE;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( base_convert  )

Definition at line 1065 of file math.c.

{
       zval **number, temp;
       long frombase, tobase;
       char *result;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zll", &number, &frombase, &tobase) == FAILURE) {
              return;
       }
       convert_to_string_ex(number);
       
       if (frombase < 2 || frombase > 36) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid `from base' (%ld)", frombase);
              RETURN_FALSE;
       }
       if (tobase < 2 || tobase > 36) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid `to base' (%ld)", tobase);
              RETURN_FALSE;
       }

       if(_php_math_basetozval(*number, frombase, &temp) == FAILURE) {
              RETURN_FALSE;
       }
       result = _php_math_zvaltobase(&temp, tobase TSRMLS_CC);
       RETVAL_STRING(result, 0);
} 

Here is the call graph for this function:

PHP_FUNCTION ( number_format  )

Definition at line 1207 of file math.c.

{
       double num;
       long dec = 0;
       char *thousand_sep = NULL, *dec_point = NULL;
       char thousand_sep_chr = ',', dec_point_chr = '.';
       int thousand_sep_len = 0, dec_point_len = 0;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|ls!s!", &num, &dec, &dec_point, &dec_point_len, &thousand_sep, &thousand_sep_len) == FAILURE) {
              return;
       }

       switch(ZEND_NUM_ARGS()) {
       case 1:
              RETURN_STRING(_php_math_number_format(num, 0, dec_point_chr, thousand_sep_chr), 0);
              break;
       case 2:
              RETURN_STRING(_php_math_number_format(num, dec, dec_point_chr, thousand_sep_chr), 0);
              break;
       case 4:
              if (dec_point != NULL) {
                     if (dec_point_len) {
                            dec_point_chr = dec_point[0];
                     } else {
                            dec_point_chr = 0;
                     }
              }
              if (thousand_sep != NULL) {
                     if (thousand_sep_len) {
                            thousand_sep_chr = thousand_sep[0];
                     } else {
                            thousand_sep_chr = 0;       
                     }
              }
              RETURN_STRING(_php_math_number_format(num, dec, dec_point_chr, thousand_sep_chr), 0);
              break;
       default:
              WRONG_PARAM_COUNT;
              break;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( fmod  )

Definition at line 1252 of file math.c.

{
       double num1, num2;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd",  &num1, &num2) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(fmod(num1, num2));
}

Here is the call graph for this function:

PHP_FUNCTION ( deg2rad  )

Definition at line 766 of file math.c.

{
       double deg;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &deg) == FAILURE) {
              return;
       }
       RETURN_DOUBLE((deg / 180.0) * M_PI);
}

Here is the call graph for this function:

PHP_FUNCTION ( rad2deg  )

Definition at line 779 of file math.c.

{
       double rad;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &rad) == FAILURE) {
              return;
       }
       RETURN_DOUBLE((rad / M_PI) * 180);
}

Here is the call graph for this function:

PHP_FUNCTION ( hypot  )

Definition at line 747 of file math.c.

{
       double num1, num2;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd", &num1, &num2) == FAILURE) {
              return;
       }
#if HAVE_HYPOT
       RETURN_DOUBLE(hypot(num1, num2));
#elif defined(_MSC_VER)
       RETURN_DOUBLE(_hypot(num1, num2));
#else
       RETURN_DOUBLE(sqrt((num1 * num1) + (num2 * num2)));
#endif
}

Here is the call graph for this function:

PHP_FUNCTION ( expm1  )

Definition at line 667 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(php_expm1(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( log1p  )

Definition at line 684 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(php_log1p(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( sinh  )

Definition at line 474 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(sinh(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( cosh  )

Definition at line 487 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(cosh(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( tanh  )

Definition at line 500 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(tanh(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( asinh  )

Definition at line 513 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(php_asinh(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( acosh  )

Definition at line 526 of file math.c.

{
       double num;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(php_acosh(num));
}

Here is the call graph for this function:

PHP_FUNCTION ( atanh  )

Definition at line 539 of file math.c.

{
       double num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &num) == FAILURE) {
              return;
       }
       RETURN_DOUBLE(php_atanh(num));
}

Here is the call graph for this function: