MATH FUNCTIONS
The standard C library math functions are provided. In all cases the mixed
$var parameters are first converted to double.
double sqrt ( mixed $var )
Determines the
square root of a number.
double ceil ( mixed $var )
This function rounds a number upwards to its nearest integer.
double floor ( mixed $var )
This function rounds a number downwards to its nearest integer.
double round ( mixed $val , int $prec )
Returns the double value of
$val rounded to the defined
$prec precision.
if
$prec is 0 or omitted,
$val is rounded to the nearest integer. The
rounding is up for positive values and down for negative. Values between
0.5 and 1.49 would round to 1.0. Values between -0.5 and -1.49 would
round to -1.0 . The
$prec specifies the number of significant places
either right of the decimal point (positive
$prec ) or left (negative
$prec ). If
$prec is 1 then
$val is rounded to the nearest tenth. If
$prec
is 2 then the value is rounded to the nearest 1/100th. If
$prec is -1
the value is rounded to the nearest 10 (5.7 rounds to 10.0).
double fabs ( mixed $var )
This returns the
absolute value of a number. The result is always a
positive value relating to the magnitude of the supplied value.
double fmod ( mixed $dividend , $mixed $divisor )
This returns the remainder of
$dividend divided by
$divisor. The
modulus operator '%' works only with integers. This is the floating
point version of the operation. This
fmod( 23.5, 5 ) returns the
value 3.5 as 5 goes into 23.5 only 4 times leaving 3.5 as the remainder.
TRIGONOMETRY
In mathematics a
transcendental function is an analytic function that does
not satisfy a polynomial equation (algebraic formula). JANOS provides the
standard exponential, logarithm and trigonometric functions. With the
trig functions (sin, cos) the parameters are given in
radians. Similarly
the arc functions (asin, acos) return radian values.
degrees = radians * 180 / pi
radians = degrees * pi / 180
pi / 2 radians = 90 degrees
Note that the function
pi() supplies a good estimate of that constant.
double pow ( mixed $var , mixed $exponent )
This function raises
$var to the power defined by
$exponent. A number
will be
squared when the exponent is 2. Similarly when the exponent
is 1/2 or 0.5 this function returns the same value as
sqrt().
JANOS scripting as of v2.5 also supports the exponentiation operator
'**' as may be found in other languages such as Basic, JavaScript and
Python. Therefore both
2 3 and
pow( 2, 3 ) return the same double
value result of 8. The '^' caret operator performs bitwise exclusive-OR.
double pi ( )
Returns 3.14159265358979323846 as best the double precision floating
point numeric encoding can provide.
double sin ( mixed $x )
Returns the sine of x (x in radians). The sine of 90 degrees or
sin( pi()/2 ) is equal to 1.
double cos ( mixed $x )
Returns the cosine of x (x in radians). The cosine of 180 degrees or
cos( pi() ) equals -1.
double tan ( mixed $x )
Returns the tangent of an angle x (x in radians). The tangent of 45
degrees or
tan( pi()/4 ) is equal to 1.
double asin ( mixed $var )
The arcsine returns the angle (in radians) whose sine is
$var. The
parameter must be in the range -1 to 1.
double acos ( mixed $var )
The arccosine returns the angle (in radians) whose cosine is
$var.
The parameter must be in the range -1 to 1.
double atan ( mixed $var )
The arctangent returns the angle (in radians) whose tangent is
var.
Since the tangent represents the ratio of the side opposite the angle
to the side adjacent to the angle (not the hypotenuse) the parameter
may be any value. For a 45 degree angle those two sides are equal with
a ratio then of 1.
atan(1) * 180 / pi() = 45
double atan2 ( mixed $opposite , mixed $adjacent )
This alternaive form of the arctangent takes as parameters the two sides
of the right triangle and returns the angle in radians.
The 30 degree right triangle is easy to remember. When the side opposite
the angle is 1 the hypotenuse is 2. Therefore the side adjacent to the
angle must be sqrt(3) in order to satisfy the Pythagorean theorem where
the square of the sides add to give the square of the hypotenuse. For this
case we have:
atan2 ( 1, sqrt(3) ) * 180/pi() = 30
EXPONENTIALS & LOGARITHMS
We frequently find situations where things increase
exponentially. For
example the computation of compound interest. The equations for such things
often involve the mathematical constant 'e' (Euler's number) which has
an approximate value of 2.71828.
double exp ( mixed $var )
The
exponential function returns the value of 'e' raised to the power
defined by
$var. We can retrieve from this the value of 'e'. Try the
following at the command line:
bruce_dev2 /> !printf( "%.15f", exp(1) );
2.718281828459043
double log ( mixed $var )
The
natural logarithm function
log() returns the power to which
the base 'e' would have to be raised to equal
$var.
log( exp(x) ) = x
log( 2.718281828459043 ) = 1
double log10 ( mixed $var )
This is the base 10 logarithm. The
log10() function returns the power
to which the base 10 would have to be raised to equal
$var.
log10( 10**x ) = x
log10( pow(10, x) ) = x
SEE ALSO
HELP Topics:
CONVERSIONS,
LIBRARY
[/flash/manpages/scripting.hlp:1064]