Chapter 3 DynaScript Predefined Objects


Math methods

The Math object has these methods:

abs method

Syntax

Math.abs( num )

Description

Returns the absolute value of a number.

Return

The absolute value of the number argument.

Example

This example returns the absolute value of -8:

<!--SCRIPT 
document.WriteLn( Math.abs( -8 ) );
-->

acos method

Syntax

Math.acos( num )

Description

Returns the arc cosine of a number.

Return

Floating point.

Example

This example returns the arc cosine of .43:

<!--SCRIPT 
document.WriteLn( Math.acos( .43 ) );
-->

asin method

Syntax

Math.asin( )

Description

Returns the arc sine of a number.

Return

Floating point.

Example

This example returns the arc sine of 1:

<!--SCRIPT 
document.WriteLn( Math.asin( 1 ) );
-->

atan method

Syntax

Math.atan( num )

Description

Returns the arc tangent of a number.

Return

Floating point.

Example

This example displays the arc tangent of .43:

<!--SCRIPT 
document.WriteLn( Math.atan( .43 ) );
-->

atan2 method

Syntax

Math.atan2( y, x )

Description

Returns the angle in radians from the x axis to the y, x point. The parameters are:

Return

Floating point.

Example

This example returns the angle from the x axis to the y, x point:

<!--SCRIPT 
document.WriteLn( Math.atan2( 3, -12 ) );
-->

ceil method

Syntax

Math.ceil( num )

Description

Returns the smallest number value that is not less than the argument and is equal to a mathematical integer.

Return

Integer.

Example

This example displays the smallest integer possible that is not less than 6.333:

<!--SCRIPT 
document.WriteLn( Math.ceil( 6.333 ) );
-->

cos method

Syntax

Math.cos( num )

Description

Returns the cosine of a number.

Return

Floating point.

Example

This example returns the cosine of 45:

<!--SCRIPT 
document.WriteLn( Math.cos( 45 ) );
-->

exp method

Syntax

Math.exp( num )

Description

Returns E raised to the power of the argument (num).

Return

Floating point.

Example

This example calculates and displays the value of E to the power of 8:

<!--SCRIPT 
document.WriteLn( Math.exp( 8 ) );
-->

floor method

Syntax

Math.floor( num )

Description

Returns the greatest number value that is not greater than the argument and is equal to a mathematical integer.

Return

Integer.

Example

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 ));
-->

log method

Syntax

Math.log( num )

Description

Returns the natural logarithm of a number.

Return

Floating point.

Example

This example displays the logarithm of the number 6:

<!--SCRIPT 
document.WriteLn( Math.log( 6 ) );
-->

max method

Syntax

Math.max( numExp, numValue )

Description

Returns the larger of two arguments. The parameters are:

Return

Floating point.

Example

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 );
-->

min method

Syntax

Math.min( numExp, numValue )

Description

Returns the smaller of the two arguments. The parameters are:

Return

Floating point.

Example

This example returns the smaller value:

<!--SCRIPT 
x = 7.543643;
y = 7.954854345;
minValue = Math.min( x, y );
document.WriteLn( minValue );
-->

pow method

Syntax

Math.pow( num, exponent )

Description

Returns the result of raising x to the power y. The parameters are:

Return

Floating point.

Example

This example returns the results of calculating 3 to the power of 8:

<!--SCRIPT 
x = Math.pow( 3, 8 );
document.WriteLn( x );
-->

random method

Syntax

Math.random( )

Description

Returns a randomly generated positive number equal to or greater than 0 but less than 1.

Return

Floating point.

Example

To return a number s equal to or greater than 0 but less than 1:

<!--SCRIPT 
x = Math.random();
document.WriteLn( x );
-->

round method

Syntax

Math.round( num )

Description

Returns the supplied number, rounded to the nearest integer.

Return

Integer.

Example

This example rounds the number 54.354 to the nearest integer:

<!--SCRIPT 
document.WriteLn( Math.round( 54.354 ) );
-->

sin method

Syntax

Math.sin( num )

Description

Returns the sine of a number.

Return

Floating point.

Example

This example displays the sine of 54:

<!--SCRIPT 
document.WriteLn( Math.sin( 54 ) );
-->

sqrt method

Syntax

Math.sqrt( num )

Description

Returns the square root of a number.

Return

Floating point.

Example

This example displays the square root of 64:

<!--SCRIPT 
document.WriteLn( Math.sqrt(64) );
-->

tan method

Syntax

Math.tan( num )

Description

Returns the tangent of a number.

Return

Floating point

Example

This example displays the tangent of 43:

<!--SCRIPT 
document.WriteLn( Math.tan( 43 ) );
-->

 


Copyright © 1999 Sybase, Inc. All rights reserved.