Math STATIC CLASS

A utility class providing various mathematical functions.

While most methods exposed by this class take untyped parameters by definition, they in fact can only handle certain number types, i.e. int, byte and float. If an argument of non-numeral type is passed in, it will in most cases result in System.ArgumentException.

Parent Class

All Members


TypeNameSignature
field S CPIpublic static const float PI
field S CEpublic static const float E
field S CINFpublic static const float INF
field S CNINFpublic static const float NINF
method Sabspublic static var abs(var)
method Sarccospublic static float arccos(var)
method Sarcsinpublic static float arcsin(var)
method Sarctanpublic static float arctan(var)
method Sceilpublic static int ceil(var)
method Scospublic static float cos(var)
method Sfloorpublic static int floor(var)
method SisNumberpublic static bool isNumber(var)
method Slogpublic static float log(var)
method Slog10public static float log10(var)
method Slog2public static float log2(var)
method Smaxpublic static var max(var, var)
method Sminpublic static var min(var, var)
method Spowerpublic static var power(var, var)
method Sroundpublic static int round(var)
method Ssignpublic static byte sign(var)
method Ssinpublic static float sin(var)
method Ssqrtpublic static float sqrt(var)
method Stanpublic static float tan(var)

Fields


public static const float PI

The ratio of a circle's circumference to its diameter.


public static const float E

The base of the natural logarithms.


public static const float INF

The positive infinity of float number.


public static const float NINF

The negative infinity of float number.


Methods


public static var abs(var v)

Get the absolute value of the numeral argument.

Parameters

  • v A numeral argument.

Returns

  • The absolute value of the argument.

Throws


public static float arccos(var v)

Get the inverse cosine of the given numeral argument.

Parameters

  • v A numeral argument.

Returns

  • The inverse cosine of the argument.

Throws


public static float arcsin(var v)

Get the inverse sine of the given numeral argument.

Parameters

  • v A numeral argument.

Returns

  • The inverse sine of the argument.

Throws


public static float arctan(var v)

Get the inverse tangent of the given numeral argument.

Parameters

  • v A numeral argument.

Returns

  • The inverse tangent of the argument.

Throws


public static int ceil(var v)

Get the smallest integer that is greater than or equal to the numeral argument.

Parameters

  • v A numeral argument.

Returns

  • The smallest integer that is greater than or equal to the argument.

Throws


public static float cos(var v)

Get the trigonometric cosine of the given numeral argument.

Parameters

  • v A numeral argument. Note this is radian value (0 - 2 * PI), not degree value (0 - 360).

Returns

  • The trigonometric cosine of the argument.

Throws


public static int floor(var v)

Get the largest integer that is less than or equal to the numeral argument.

Parameters

  • v A numeral argument.

Returns

  • The largest integer that is less than or equal to the argument.

Throws


public static bool isNumber(var v)

Check whether a value is a number. A value of int or byte type is a number. A float value is usually also a number except if it explicitly represents Not-A-Number, which can happen when an arithmetic expression yielded illegal intermediate or final result.

Parameters

  • v The value to be checked.

Returns

  • True if this value is a number; false if not.

public static float log(var v)

Get the natural logarithm (with base = e) of the given numeral argument.

This class also provides two convenient log methods for base-2 and base-10. To perform logarithm calculation of arbitrary base B, simply do log(x)/log(B).

Parameters

  • v A numeral argument.

Returns

  • The natural logarithm of the argument.

Throws


public static float log10(var v)

Get the logarithm with base = 10 of the given numeral argument.

Parameters

  • v A numeral argument.

Returns

  • The base-10 logarithm of the argument.

Throws


public static float log2(var v)

Get the logarithm with base = 2 of the given numeral argument.

Parameters

  • v A numeral argument.

Returns

  • The base-2 logarithm of the argument.

Throws


public static var max(var v1, var v2)

Get the larger one from the two arguments. If the two are equal the same value will be returned.

Parameters

  • v1 The first value.
  • v2 The second value.

Returns

  • The larger value out of the two.

Throws


public static var min(var v1, var v2)

Get the smaller one from the two arguments. If the two are equal the same value will be returned.

Parameters

  • v1 The first value.
  • v2 The second value.

Returns

  • The smaller value out of the two.

Throws


public static var power(var a, var b)

Raise one value to the power of another.

Parameters

  • a The base.
  • b The exponent.

Returns

  • The base valued raised to the power of the exponent value.

Throws


public static int round(var v)

Get the closest integer to the numeral argument.

The given value will be rounded half towards positive infinity. This means for a positive number, if the decimal part is equal to or greater than 0.5, it will be rounded up; otherwise rounded down. For a negative number, if the decimal part is equal to or less than -0.5, it will be rounded up; otherwise rounded down. Some examples: round(1.4) = 1, round(1.5) = 2, round(1.6) = 2; round(-1.4) = -1, round(-1.5) = -1, round(-1.6) = -2.

Parameters

  • v A numeral argument.

Returns

  • The smallest integer that is greater than or equal to the argument.

Throws


public static byte sign(var v)

Get the sign part of the given numeral argument.

Parameters

  • v A numeral argument.

Returns

  • 1 if positive or 0; -1 otherwise.

Throws


public static float sin(var v)

Get the trigonometric sine of the given numeral argument.

Parameters

  • v A numeral argument. Note this is radian value (0 - 2 * PI), not degree value (0 - 360).

Returns

  • The trigonometric sine of the argument.

Throws


public static float sqrt(var v)

Get the square root of the given numeral argument.

Parameters

  • v A numeral argument.

Returns

  • The square root of the argument.

Throws


public static float tan(var v)

Get the trigonometric tangent of the given numeral argument.

Parameters

  • v A numeral argument. Note this is radian value (0 - 2 * PI), not degree value (0 - 360).

Returns

  • The trigonometric tangent of the argument.

Throws