Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

Chapter 10. MATHEMATICAL FUNCTIONS


Common Math...................................................................................................


Random Numbers............................................................................................


Arbitrary-Precision Numbers........................................................................


The math functions fall into three categories: common mathematical operations, random
numbers, and special functions for handling numbers of arbitrary precision.


Common Math


The functions in this section offer most of the common mathematical operations that are
part of arithmetic, geometry, and trigonometry. Most of these functions work on either
doubles or integers. The return type will be the same as the argument. Unless a specific
type is called for, I've written "number" to indicate that either an integer or a double is
expected.


number abs(number value)


The abs function returns the absolute value of a number. This is the number itself if it's
positive, or the number multiplied by negative one (-1) if negative.


<?
//prints 13
print(abs(-13));
?>


double acos(double value)


The acos function returns the arc cosine of the value argument. Trying to find the arc
cosine of a value greater than one or less than negative one is undefined.


Figure 10-1. acos.
Free download pdf