Chapter 3 DynaScript Predefined Objects
The Math object provides basic Math functionality to users.
Standard: ECMAScript
To use a Math property:
Math.propertyName
To use a Math method:
Math.MethodName( parameter )
The Math object provides basic math functionality in your PowerDynamo script or template.
The Math object is provided as a built-in object. There are no constructors for creating instances of a Math object. When referring to Math in this chapter, we are referring to the built-in Math object, not an instance of the Math object.
This example uses the pow
method
of the Math object and displays the results:
<!--SCRIPT ans = Math.pow( 4, 3 ); document.WriteLn(ans) -->
Math.E
This property is read-only.
Returns the number value for e, the base of the natural logarithms, which is approximately 2.71828182845905.
Floating point
To display the value of e:
<!--SCRIPT a = Math.E; document.WriteLn( a ); -->
Math.LN2
This property is read-only.
Returns the number value for the natural logarithm of 2, which is approximately 0.693147180559945.
Floating point
To display the value of LN2:
<!--SCRIPT a = Math.LN2; document.WriteLn( a ); -->
Math.LN10
This property is read-only.
Returns the value for the natural logarithm of 10, which is approximately 2.30258509299405.
Floating point
To display the value of LN10:
<!--SCRIPT a = Math.LN10; document.WriteLn( a ); -->
Math.LOG2E
This property is read-only.
Returns the number value for the base-2 logarithm of e, Euler's constant. This value is approximately 1.44269504088896.
Floating point
To display the value of LOG2E:
<!--SCRIPT a = Math.LOG2E; document.WriteLn( a ); -->
Math.LOG10E
This property is read-only.
Returns the number value for the base-10 logarithm of e, Euler's constant. This value is approximately 0.434294481903252.
Floating point
To display the value of LOG10E:
<!--SCRIPT a = Math.LOG10E; document.WriteLn( a ); -->
Math.PI
This property is read-only.
Returns the ratio of the circumference of a circle to its diameter, which is approximately 3.14159265358979.
Floating point
To display the value of PI:
<!--SCRIPT a = Math.PI; document.WriteLn( a ); -->
Math.SQRT1_2
This property is read-only.
Returns the number value for the square root of 1/2, which is approximately 0.707106781186548.
Floating point
To display the value of the square root of 1/2:
<!--SCRIPT a = Math.SQRT1_2; document.WriteLn( a ); -->
Math.SQRT2
This property is read-only.
Returns the number value for the square root of 2, which is approximately 1.4142135623731.
Floating point
To display the value of the square root of 2:
<!--SCRIPT a = Math.SQRT2; document.WriteLn( a ); -->
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 © 2001 Sybase, Inc. All rights reserved. |
![]() |