Math

Description

A class containing common math functions.

Static Properties

pi Gets an approximate value for pi.

Static Methods

acos Returns the arc cosine of an angle in radians.
asin Returns the arc sine of an angle in radians.
atan Returns the arc tangent of an angle in radians.
atan2 Returns the arc tangent of an angle in radians.
ceil Returns the smallest integer value not less than value.
cos Returns the cosine of an angle in radians.
degrees Converts an angle in radians to degrees.
exp Returns (e ^ value) where e is 2.7183
fabs Returns the absolute value of the number.
factorial Returns the factorial of the number.
floor Returns the largest integer value not larger than the number.
fmod Returns the remainder of dividing the numerator by the denominator.
frac Returns the decimal part of a number.
log Returns the natural logarithm of a number.
log10 Returns the base-10 logarithm of a number.
max Returns the greater of two numbers.
min Returns the lesser of two numbers.
pow Returns the base raised to the power of the exponent.
radians Converts an angle in degrees to radians.
round Rounds the value to the specified precision.
sign Returns the sign of the number.
sin Returns the sine of an angle in radians.
sqr Returns the number squared.
sqrt Returns the square root of the number.
tan Returns the tangent of an angle in radians.
trunc Removes the fractional part of the number.

Details

Do no remove, this fixes the anchor on doc.flexsim.com

Math.pi

static double pi

Description

Gets an approximate value for pi.

The internal representation is 3.14159265358979.

Math.cos(Math.pi) // -1
Do no remove, this fixes the anchor on doc.flexsim.com

Math.acos()

static double acos( double ratio )

Parameters

ratio The ratio - adjacent/hypotenuse - of a right triangle.

Returns

double The arc cosine of the angle in radians.

Description

Returns the arc cosine of an angle in radians.

acos() is the inverse of the cos() method. Ratio should never be less than -1 or greater than 1.

double angle = Math.degrees(Math.acos(xdist / totaldist));
Do no remove, this fixes the anchor on doc.flexsim.com

Math.asin()

static double asin( double ratio )

Parameters

ratio The ratio - opposite/hypotenuse - of a right triangle.

Returns

double The arc sine of the angle in radians.

Description

Returns the arc sine of an angle in radians.

asin() is the inverse of the sin() method. Ratio should never be less than -1 or greater than 1.

double angle = Math.degrees(Math.asin(ydist / totaldist));
Do no remove, this fixes the anchor on doc.flexsim.com

Math.atan()

static double atan( double ratio )

Parameters

ratio The ratio - opposite/adjacent - of a right triangle.

Returns

double The arc tangent of the angle in radians.

Description

Returns the arc tangent of an angle in radians.

atan() is the inverse of the tan() method. Ratio should be within the interval [-pi/2,+ pi/2]. Notice that because of the sign ambiguity, the atan() method cannot determine with certainty in which quadrant the angle falls only by its tangent value. You can use the atan2() method if you need to determine the quadrant.

double theArcTangent = Math.atan(Math.radians(45)); //0.6658
Do no remove, this fixes the anchor on doc.flexsim.com

Math.atan2()

static double atan2( double dy , double dx )

Parameters

dy The length of the "opposite" side of a right triangle.
dx The length of the "adjacent" side of a right triangle.

Returns

double The arc tangent of the angle in radians.

Description

Returns the arc tangent of an angle in radians.

The returned angle will increase from 0 to pi/2 beginning at the positive x axis in a counter-clockwise direction, and will decrease from 0 to -pi/2 in a clockwise direction. If both parameters of atan2 are 0, the function returns 0. atan2 is well defined for every point other than the origin, even if value1 equals 0 and value2 does not equal 0.

double theAngle = Math.degrees(Math.atan2(-1,1.732)); // -30
Do no remove, this fixes the anchor on doc.flexsim.com

Math.ceil()

static int ceil( double value )

Parameters

value The value to ceiling.

Returns

int The smallest integer value not less than value.

Description

Returns the smallest integer value not less than value.

double myval = Math.ceil(2.3); // 3.double myval = Math.ceil(3.8); // 4.double myval = Math.ceil(-2.3); // -2.double myval = Math.ceil(-3.8); // -3.

See also floor().

Do no remove, this fixes the anchor on doc.flexsim.com

Math.cos()

static double cos( double angle )

Parameters

angle The angle in radians.

Returns

double The cosine of the angle in radians.

Description

Returns the cosine of an angle in radians.

The angle should be less than 263 radians and greater than -263 radians to avoid loss of significance in the result.

double theCosine = Math.cos(Math.radians(180)); //-1

See also acos().

Do no remove, this fixes the anchor on doc.flexsim.com

Math.degrees()

static double degrees( double angle )

Parameters

angle The angle in radians.

Returns

double The angle in degrees.

Description

Converts an angle in radians to degrees.

One radian is 180/pi degrees (~57.2958).

double degrees = Math.degrees(Math.pi); // 180

See also radians().

Do no remove, this fixes the anchor on doc.flexsim.com

Math.exp()

static double exp( double exponent )

Parameters

exponent The exponent of e.

Returns

double e raised to an exponent.

Description

Returns (e ^ value) where e is 2.7183

On overflow, the function returns INF (infinite) and on underflow, exp returns 0.

double value = Math.exp(3); // 20.0855

See also log() which is the inverse of exp().

Do no remove, this fixes the anchor on doc.flexsim.com

Math.fabs()

static double fabs( double value )

Parameters

value The passed in value.

Returns

double The absolute value of the number.

Description

Returns the absolute value of the number.

This code checks if the operator is within 5 units of the current object along the x-axis.

if(Math.fabs(current.location.x - operator.location.x) < 5)
Do no remove, this fixes the anchor on doc.flexsim.com

Math.factorial()

static double factorial( double value )

Parameters

value The passed in value.

Returns

double The factorial of the number.

Description

Returns the factorial of the number.

double val = Math.factorial(5); // 120 = 1*2*3*4*5
Do no remove, this fixes the anchor on doc.flexsim.com

Math.floor()

static int floor( double value )

Parameters

value The passed in value.

Returns

int The largest integer value not larger than the number.

Description

Returns the largest integer value not larger than the number.

double myval = Math.floor(2.3); // 2.double myval = Math.floor(3.8); // 3.double myval = Math.floor(-2.3); // -3.double myval = Math.floor(-3.8); // -4.

See also ceil() and trunc().

Do no remove, this fixes the anchor on doc.flexsim.com

Math.fmod()

static double fmod( double numerator , double denominator )

Parameters

numerator The value being divided.
denominator The value to divide by.

Returns

double The remainder of dividing the numerator by the denominator.

Description

Returns the remainder of dividing the numerator by the denominator.

If the denominator is 0.0, fmod returns a quiet NaN.

Math.fmod(10,3) // 1.0

This method is great for getting a repeating set of numbers. So long as the denominator is unchanged, incrementing the numerator and calling fmod will return a set of numbers that keeps repeating itself between 0 and 1 minus the denominator. The following condition, if used in the OnExit of an object in the model, would be true with every 10th flowitem that exits, starting with the 10th flowitem.

if(Math.fmod(current.stats.output.value,10) == 0)
Do no remove, this fixes the anchor on doc.flexsim.com

Math.frac()

static double frac( double value )

Parameters

value The passed in value.

Returns

double The decimal part of the specified floating point value.

Description

Returns the decimal part of a number.

Math.frac(3.124) // 0.124Math.frac(-16.12) // -0.12Math.frac(12) // 0.0
Do no remove, this fixes the anchor on doc.flexsim.com

Math.log()

static double log( double value )

Parameters

value The passed in value.

Returns

double The natural logarithm of a number.

Description

Returns the natural logarithm of a number.

If value is negative, this function returns an indefinite (same as a quiet NaN). If value is 0, it returns INF (infinite).

Math.log(9); // 2.1972

log() is the inverse of the exp() method.

Math.log(Math.exp(3.2)); // 3.2
Do no remove, this fixes the anchor on doc.flexsim.com

Math.log10()

static double log10( double value )

Parameters

value The passed in value.

Returns

double The base-10 logarithm of a number.

Description

Returns the base-10 logarithm of a number.

If value is negative, this function returns an indefinite (same as a quiet NaN). If value is 0, it returns INF (infinite).

Math.log10(1000); // 3

log10() is the inverse of the pow() method with base 10.

Math.log10(Math.pow(10, 3.2)); // 3.2
Do no remove, this fixes the anchor on doc.flexsim.com

Math.max()

static double max( double value1 , double value2 )

Parameters

value1 The first value to compare.
value2 The second value to compare.

Returns

double The greater of two numbers.

Description

Returns the greater of two numbers.

double max = Math.max(6,7); // 7

The following code will generate a normally distributed random number between and inclusive of 0 and 100:

double haulLoad = Math.min(Math.max(normal(55, 27), 0), 100);

See also min().

Do no remove, this fixes the anchor on doc.flexsim.com

Math.min()

static double min( double value1 , double value2 )

Parameters

value1 The first value to compare.
value2 The second value to compare.

Returns

double The lesser of two numbers.

Description

Returns the lesser of two numbers.

double min = Math.min(6,7); // 6

The following code will generate a normally distributed random number between and inclusive of 0 and 100:

double haulLoad = Math.min(Math.max(normal(55, 27), 0), 100);

See also max().

Do no remove, this fixes the anchor on doc.flexsim.com

Math.pow()

static double pow( double base , double exponent )

Parameters

base The value being raised to a power.
exponent The exponent the base will be raised to.

Returns

double The base raised to the power of the exponent.

Description

Returns the base raised to the power of the exponent.

double myval = Math.pow(2,3); // 8.
Do no remove, this fixes the anchor on doc.flexsim.com

Math.radians()

static double radians( double angle )

Parameters

angle The angle in degrees.

Returns

double The angle in radians.

Description

Converts an angle in degrees to radians.

1 degree is pi/180 radians.

double radians = Math.radians(180); // 3.1415 (pi)

See also degrees().

Do no remove, this fixes the anchor on doc.flexsim.com

Math.round()

static double round( double value , int precision = 0 )

Parameters

value The value being rounded.
precision The number of decimal places to round to.

Returns

double The value rounded to the specified precision.

Description

Rounds the value to the specified precision.

A fractional part 0 < f < 0.5 will be rounded down. A fractional part 0.5 <= f < 1.0 will be rounded up. Using a precision of 0 (or not specifying it) will round to the nearest integer.

int myNum = Math.round(3.6269); // 4int myNum = Math.round(3.6269, 2); // 3.63
Do no remove, this fixes the anchor on doc.flexsim.com

Math.sign()

static int sign( double value )

Parameters

value The passed in value.

Returns

int The sign of the number.

Description

Returns the sign of the number.

int sign = Math.sign(-100); // -1int sign = Math.sign(100); // 1int sign = Math.sign(0); // 0
Do no remove, this fixes the anchor on doc.flexsim.com

Math.sin()

static double sin( double angle )

Parameters

angle The angle in radians.

Returns

double The sine of the angle in radians.

Description

Returns the sine of an angle in radians.

The angle should be less than 263 radians and greater than -263 radians to avoid loss of significance in the result.

double theSine = Math.sin(Math.radians(90)); // 1

See also asin().

Do no remove, this fixes the anchor on doc.flexsim.com

Math.sqr()

static double sqr( double value )

Parameters

value The passed in value.

Returns

double The number squared.

Description

Returns the number squared.

int square = Math.sqr(4); // 16

See also sqrt().

Do no remove, this fixes the anchor on doc.flexsim.com

Math.sqrt()

static double sqrt( double value )

Parameters

value The passed in value.

Returns

double The square root of the number.

Description

Returns the square root of the number.

int root = Math.sqrt(25); // 5

See also sqr().

Do no remove, this fixes the anchor on doc.flexsim.com

Math.tan()

static double tan( double angle )

Parameters

angle The angle in radians.

Returns

double The tangent of the angle in radians.

Description

Returns the tangent of an angle in radians.

The angle should be less than 263 radians and greater than -263 radians to avoid loss of significance in the result.

double theTangent = Math.tan(Math.radians(45)); // 1

See also atan().

Do no remove, this fixes the anchor on doc.flexsim.com

Math.trunc()

static int trunc( double value )

Parameters

value The passed in value.

Returns

int The fractional part of the number.

Description

Removes the fractional part of the number.

Truncates the value.

int val = Math.trunc(2.478); // 2int sign = Math.sign(2.95); // 2

See also round().