Chapter 3 DynaScript Predefined Objects
The Math
object
has these methods:
Math.abs( num )
Returns the absolute value of a number.
The absolute value of the number argument.
This example returns the absolute value of -8:
<!--SCRIPT
document.WriteLn( Math.abs( -8 ) );
-->
Math.acos( num )
Returns the arc cosine of a number.
Floating point.
This example returns the arc cosine of .43:
<!--SCRIPT
document.WriteLn( Math.acos( .43 ) );
-->
Math.asin( )
Returns the arc sine of a number.
Floating point.
This example returns the arc sine of 1:
<!--SCRIPT
document.WriteLn( Math.asin( 1 ) );
-->
Math.atan( num )
Returns the arc tangent of a number.
Floating point.
This example displays the arc tangent of .43:
<!--SCRIPT
document.WriteLn( Math.atan( .43 ) );
-->
Math.atan2( y, x )
Returns the angle in radians from the x axis to the y, x point. The parameters are:
Floating point.
This example returns the angle from the x axis to the y, x point:
<!--SCRIPT
document.WriteLn( Math.atan2( 3, -12 ) );
-->
Math.ceil( num )
Returns the smallest number value that is not less than the argument and is equal to a mathematical integer.
Integer.
This example displays the smallest integer possible that is not less than 6.333:
<!--SCRIPT
document.WriteLn( Math.ceil( 6.333 ) );
-->
Math.cos( num )
Returns the cosine of a number.
Floating point.
This example returns the cosine of 45:
<!--SCRIPT
document.WriteLn( Math.cos( 45 ) );
-->
Math.exp( num )
Returns E raised to the power of the argument (num).
Floating point.
This example calculates and displays the value of E to the power of 8:
<!--SCRIPT
document.WriteLn( Math.exp( 8 ) );
-->
Math.floor( num )
Returns the greatest number value that is not greater than the argument and is equal to a mathematical integer.
Integer.
This example calculates and displays the greatest number value that is not greater than the argument and is equal to a mathematical integer:
<!--SCRIPT
document.WriteLn( Math.floor( 634.8 ));
-->
Math.log( num )
Returns the natural logarithm of a number.
Floating point.
This example displays the logarithm of the number 6:
<!--SCRIPT
document.WriteLn( Math.log( 6 ) );
-->
Math.max( numExp, numValue )
Returns the larger of two arguments. The parameters are:
Floating point.
This example returns the larger value of x and y:
<!--SCRIPT
x = 7.543643;
y = 7.954854345;
minValue = Math.max( x, y );
document.WriteLn( minValue );
-->
Math.min( numExp, numValue )
Returns the smaller of the two arguments. The parameters are:
Floating point.
This example returns the smaller value:
<!--SCRIPT
x = 7.543643;
y = 7.954854345;
minValue = Math.min( x, y );
document.WriteLn( minValue );
-->
Math.pow( num, exponent )
Returns the result of raising x to the power y. The parameters are:
Floating point.
This example returns the results of calculating 3 to the power of 8:
<!--SCRIPT
x = Math.pow( 3, 8 );
document.WriteLn( x );
-->
Math.random( )
Returns a randomly generated positive number equal to or greater than 0 but less than 1.
Floating point.
To return a number s equal to or greater than 0 but less than 1:
<!--SCRIPT
x = Math.random();
document.WriteLn( x );
-->
Math.round( num )
Returns the supplied number, rounded to the nearest integer.
Integer.
This example rounds the number 54.354 to the nearest integer:
<!--SCRIPT
document.WriteLn( Math.round( 54.354 ) );
-->
Math.sin( num )
Returns the sine of a number.
Floating point.
This example displays the sine of 54:
<!--SCRIPT
document.WriteLn( Math.sin( 54 ) );
-->
Math.sqrt( num )
Returns the square root of a number.
Floating point.
This example displays the square root of 64:
<!--SCRIPT
document.WriteLn( Math.sqrt(64) );
-->
Math.tan( num )
Returns the tangent of a number.
Floating point
This example displays the tangent of 43:
<!--SCRIPT
document.WriteLn( Math.tan( 43 ) );
-->
Copyright © 1999 Sybase, Inc. All rights reserved. |