Math type
  • 28 Nov 2022
  • 1 Minute to read
  • Contributors
  • Dark
    Light

Math type

  • Dark
    Light

Article Summary

The math type provides trigonometric and other advanced mathematical functions and constants. For commonly used, simple mathematical functions take a look at the number type.

Usage

To use any of the functions described on this page, you must prefix them with the math type name.

Math.sin(90)

And if you already named something else "Math", you need an additional prefix.

HiveTypes.Math.sin(90)

Constants

namedescription
pithe number pi
ethe number e (natural logarithmic base)

Functions

namedescription
abs(number)
gets the absolute value of a number
sqrt(number)
gets the square root of a number
random(max)
gets a random number
max(number1, number2) 
gets the greater of two numbers
min(number1, number2)
gets the lower of two numbers

Trigonometric Functions (in degrees)

These functions assume that angles are measured in degrees, see the next section for corresponding functions that take radians.

namedescription
sin(angle)gets the sine of the speicified angle
cos(angle)gets the cosine of the specified angle
tan(angle)gets the tangent of a specified angle
asin(number)gets the angle whose sine is the speicified number
acos(number)gets the angle whose cosine is the specified number
atan(number)gets the angle whose tangent is the specified number

Trigonometric Functions (in radians)

These functions assume that angles are measured in radians, otherwise they behave exactly like their degree counterparts.

namedescription
sinr(angle)gets the sine of the specified angle
cosr(angle)gets the cosine of the specified angle
tanr(angle)gets the tangent of a specified angle
asinr(number)gets the angle whose sine is the speicified number
acosr(number)gets the angle whose cosine is the specified number
atanr(number)gets the angle whose tangent is the specified number

abs(number)

Returns the absolute value of a number.

exampleresult
Math.abs(-13.37)13.37
Math.abs(5)5

sqrt(number)

Returns the square root of a number.

exampleresult
Math.sqrt(4)2

random(max)

Returns a random number between zero and the specified maximum. If no maximum is specified, 2147483647 is used.

exampleresult
Math.random(5)a number between 0 and 4

max(number1, number2)

Returns the greater of two numbers.

exampleresult
Math.max(3, 5)5
Math.max(-7, -2)-2

min(number1, number2)

Returns the lesser of two numbers.

exampleresult
Math.min(3, 5)3
Math.min(-7, -2)-7



Was this article helpful?

What's Next