php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
math.c File Reference
#include "php.h"
#include "php_math.h"
#include "zend_bitset.h"
#include "zend_enum.h"
#include "zend_exceptions.h"
#include "zend_multiply.h"
#include "zend_portability.h"
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include "basic_functions.h"

Go to the source code of this file.

Functions

PHPAPI double _php_math_round (double value, int places, int mode)
 
 PHP_FUNCTION (abs)
 
 PHP_FUNCTION (ceil)
 
 PHP_FUNCTION (floor)
 
PHPAPI int php_math_round_mode_from_enum (zend_object *mode)
 
 PHP_FUNCTION (round)
 
 PHP_FUNCTION (sin)
 
 PHP_FUNCTION (cos)
 
 PHP_FUNCTION (tan)
 
 PHP_FUNCTION (asin)
 
 PHP_FUNCTION (acos)
 
 PHP_FUNCTION (atan)
 
 PHP_FUNCTION (atan2)
 
 PHP_FUNCTION (sinh)
 
 PHP_FUNCTION (cosh)
 
 PHP_FUNCTION (tanh)
 
 PHP_FUNCTION (asinh)
 
 PHP_FUNCTION (acosh)
 
 PHP_FUNCTION (atanh)
 
 PHP_FUNCTION (pi)
 
 PHP_FUNCTION (is_finite)
 
 PHP_FUNCTION (is_infinite)
 
 PHP_FUNCTION (is_nan)
 
 PHP_FUNCTION (pow)
 
 PHP_FUNCTION (exp)
 
 PHP_FUNCTION (expm1)
 
 PHP_FUNCTION (log1p)
 
 PHP_FUNCTION (log)
 
 PHP_FUNCTION (log10)
 
 PHP_FUNCTION (sqrt)
 
 PHP_FUNCTION (hypot)
 
 PHP_FUNCTION (deg2rad)
 
 PHP_FUNCTION (rad2deg)
 
PHPAPI zend_long _php_math_basetolong (zval *arg, int base)
 
PHPAPI void _php_math_basetozval (zend_string *str, int base, zval *ret)
 
PHPAPI zend_string_php_math_longtobase (zend_long arg, int base)
 
PHPAPI zend_string_php_math_zvaltobase (zval *arg, int base)
 
 PHP_FUNCTION (bindec)
 
 PHP_FUNCTION (hexdec)
 
 PHP_FUNCTION (octdec)
 
 PHP_FUNCTION (decbin)
 
 PHP_FUNCTION (decoct)
 
 PHP_FUNCTION (dechex)
 
 ZEND_FRAMELESS_FUNCTION (dechex, 1)
 
 PHP_FUNCTION (base_convert)
 
PHPAPI zend_string_php_math_number_format (double d, int dec, char dec_point, char thousand_sep)
 
PHPAPI zend_string_php_math_number_format_ex (double d, int dec, const char *dec_point, size_t dec_point_len, const char *thousand_sep, size_t thousand_sep_len)
 
PHPAPI zend_string_php_math_number_format_long (zend_long num, zend_long dec, const char *dec_point, size_t dec_point_len, const char *thousand_sep, size_t thousand_sep_len)
 
 PHP_FUNCTION (number_format)
 
 PHP_FUNCTION (fmod)
 
 PHP_FUNCTION (fdiv)
 
 PHP_FUNCTION (fpow)
 
 PHP_FUNCTION (intdiv)
 

Variables

PHPAPI zend_class_entryrounding_mode_ce
 

Function Documentation

◆ _php_math_basetolong()

PHPAPI zend_long _php_math_basetolong ( zval * arg,
int base )

Definition at line 752 of file math.c.

◆ _php_math_basetozval()

PHPAPI void _php_math_basetozval ( zend_string * str,
int base,
zval * ret )

Definition at line 796 of file math.c.

◆ _php_math_longtobase()

PHPAPI zend_string * _php_math_longtobase ( zend_long arg,
int base )

Definition at line 875 of file math.c.

◆ _php_math_number_format()

PHPAPI zend_string * _php_math_number_format ( double d,
int dec,
char dec_point,
char thousand_sep )

Definition at line 1098 of file math.c.

◆ _php_math_number_format_ex()

PHPAPI zend_string * _php_math_number_format_ex ( double d,
int dec,
const char * dec_point,
size_t dec_point_len,
const char * thousand_sep,
size_t thousand_sep_len )

Definition at line 1103 of file math.c.

◆ _php_math_number_format_long()

PHPAPI zend_string * _php_math_number_format_long ( zend_long num,
zend_long dec,
const char * dec_point,
size_t dec_point_len,
const char * thousand_sep,
size_t thousand_sep_len )

Definition at line 1221 of file math.c.

◆ _php_math_round()

PHPAPI double _php_math_round ( double value,
int places,
int mode )

When extracting the integer part, the result may be incorrect as a decimal number due to floating point errors. e.g. 0.285 * 10000000000 => 2849999999.9999995 floor(0.285 * 10000000000) => 2849999999

Add 1 to the absolute value of the value adjusted by floor or ceil, use the exponent to return it to its original precision, and compare it with value. If it is equal to value, it is assumed that the absolute value is 1 smaller due to error and will be corrected. e.g. 0.285 * 10000000000 => 2849999999.9999995 floor(0.285 * 10000000000) => 2849999999 (tmp_value) tmp_value2 = 2849999999 + 1 => 2850000000 2850000000 / 10000000000 == 0.285 => true tmp_value = tmp_value2

Definition at line 167 of file math.c.

◆ _php_math_zvaltobase()

PHPAPI zend_string * _php_math_zvaltobase ( zval * arg,
int base )

Definition at line 941 of file math.c.

◆ PHP_FUNCTION() [1/43]

PHP_FUNCTION ( abs )

Definition at line 247 of file math.c.

◆ PHP_FUNCTION() [2/43]

PHP_FUNCTION ( acos )

Definition at line 441 of file math.c.

◆ PHP_FUNCTION() [3/43]

PHP_FUNCTION ( acosh )

Definition at line 526 of file math.c.

◆ PHP_FUNCTION() [4/43]

PHP_FUNCTION ( asin )

Definition at line 429 of file math.c.

◆ PHP_FUNCTION() [5/43]

PHP_FUNCTION ( asinh )

Definition at line 514 of file math.c.

◆ PHP_FUNCTION() [6/43]

PHP_FUNCTION ( atan )

Definition at line 453 of file math.c.

◆ PHP_FUNCTION() [7/43]

PHP_FUNCTION ( atan2 )

Definition at line 465 of file math.c.

◆ PHP_FUNCTION() [8/43]

PHP_FUNCTION ( atanh )

Definition at line 538 of file math.c.

◆ PHP_FUNCTION() [9/43]

PHP_FUNCTION ( base_convert )

Definition at line 1065 of file math.c.

◆ PHP_FUNCTION() [10/43]

PHP_FUNCTION ( bindec )

Definition at line 976 of file math.c.

◆ PHP_FUNCTION() [11/43]

PHP_FUNCTION ( ceil )

Definition at line 270 of file math.c.

◆ PHP_FUNCTION() [12/43]

PHP_FUNCTION ( cos )

Definition at line 405 of file math.c.

◆ PHP_FUNCTION() [13/43]

PHP_FUNCTION ( cosh )

Definition at line 490 of file math.c.

◆ PHP_FUNCTION() [14/43]

PHP_FUNCTION ( decbin )

Definition at line 1015 of file math.c.

◆ PHP_FUNCTION() [15/43]

PHP_FUNCTION ( dechex )

Definition at line 1041 of file math.c.

◆ PHP_FUNCTION() [16/43]

PHP_FUNCTION ( decoct )

Definition at line 1028 of file math.c.

◆ PHP_FUNCTION() [17/43]

PHP_FUNCTION ( deg2rad )

Definition at line 724 of file math.c.

◆ PHP_FUNCTION() [18/43]

PHP_FUNCTION ( exp )

Definition at line 609 of file math.c.

◆ PHP_FUNCTION() [19/43]

PHP_FUNCTION ( expm1 )

Definition at line 622 of file math.c.

◆ PHP_FUNCTION() [20/43]

PHP_FUNCTION ( fdiv )

Definition at line 1413 of file math.c.

◆ PHP_FUNCTION() [21/43]

PHP_FUNCTION ( floor )

Definition at line 289 of file math.c.

◆ PHP_FUNCTION() [22/43]

PHP_FUNCTION ( fmod )

Definition at line 1395 of file math.c.

◆ PHP_FUNCTION() [23/43]

PHP_FUNCTION ( fpow )

Definition at line 1427 of file math.c.

◆ PHP_FUNCTION() [24/43]

PHP_FUNCTION ( hexdec )

Definition at line 989 of file math.c.

◆ PHP_FUNCTION() [25/43]

PHP_FUNCTION ( hypot )

Definition at line 710 of file math.c.

◆ PHP_FUNCTION() [26/43]

PHP_FUNCTION ( intdiv )

Definition at line 1441 of file math.c.

◆ PHP_FUNCTION() [27/43]

PHP_FUNCTION ( is_finite )

Definition at line 559 of file math.c.

◆ PHP_FUNCTION() [28/43]

PHP_FUNCTION ( is_infinite )

Definition at line 571 of file math.c.

◆ PHP_FUNCTION() [29/43]

PHP_FUNCTION ( is_nan )

Definition at line 583 of file math.c.

◆ PHP_FUNCTION() [30/43]

PHP_FUNCTION ( log )

Definition at line 648 of file math.c.

◆ PHP_FUNCTION() [31/43]

PHP_FUNCTION ( log10 )

Definition at line 684 of file math.c.

◆ PHP_FUNCTION() [32/43]

PHP_FUNCTION ( log1p )

Definition at line 635 of file math.c.

◆ PHP_FUNCTION() [33/43]

PHP_FUNCTION ( number_format )

Definition at line 1340 of file math.c.

◆ PHP_FUNCTION() [34/43]

PHP_FUNCTION ( octdec )

Definition at line 1002 of file math.c.

◆ PHP_FUNCTION() [35/43]

PHP_FUNCTION ( pi )

Definition at line 550 of file math.c.

◆ PHP_FUNCTION() [36/43]

PHP_FUNCTION ( pow )

Definition at line 595 of file math.c.

◆ PHP_FUNCTION() [37/43]

PHP_FUNCTION ( rad2deg )

Definition at line 736 of file math.c.

◆ PHP_FUNCTION() [38/43]

PHP_FUNCTION ( round )

Definition at line 334 of file math.c.

◆ PHP_FUNCTION() [39/43]

PHP_FUNCTION ( sin )

Definition at line 393 of file math.c.

◆ PHP_FUNCTION() [40/43]

PHP_FUNCTION ( sinh )

Definition at line 478 of file math.c.

◆ PHP_FUNCTION() [41/43]

PHP_FUNCTION ( sqrt )

Definition at line 697 of file math.c.

◆ PHP_FUNCTION() [42/43]

PHP_FUNCTION ( tan )

Definition at line 417 of file math.c.

◆ PHP_FUNCTION() [43/43]

PHP_FUNCTION ( tanh )

Definition at line 502 of file math.c.

◆ php_math_round_mode_from_enum()

PHPAPI int php_math_round_mode_from_enum ( zend_object * mode)

Definition at line 307 of file math.c.

◆ ZEND_FRAMELESS_FUNCTION()

ZEND_FRAMELESS_FUNCTION ( dechex ,
1  )

Definition at line 1053 of file math.c.

Variable Documentation

◆ rounding_mode_ce

PHPAPI zend_class_entry* rounding_mode_ce

Definition at line 34 of file math.c.