This site has been deprecated. Do not edit pages here. Please visit the new Pico Labs documentation.


Skip to end of metadata
Go to start of metadata

The math library provides a number of useful math functions as well as special functions for plane-angle conversions, digests, trigonometry, and great-circle calculations. More are added as needed. 

General Functions

random

random(<num>) - generate a random number. The value is between 0 and the number given as an argument.

The given example will return random digits between 0 and 3 inclusive:

exponent

exp(<num>) - return e (natural logrithm) raised to the <num>th power

int

int(<num>) - the integer value of <num>

absolute value

abs(<num>) - absolute value of <num>

logarithm

log(<num>) - natural log of <num>

square root

sqrt(<num>) - square root of <num>

power

power(<num1>,<num1>) - <num1> to the <num2>th power.

ceiling

ceiling(<num>) - the smallest integer not less than <num>

floor

floor(<num>) - the largest integer not greater than <num>

round

round(<num> - convert <num> to the nearest integer.

 

Plane Angle Conversions

deg2rad

deg2rad(<num>) - convert degrees to radians

grad2rad

grad2rad(<num>) - convert gradians to radians

rad2deg

rad2deg(<num>) - convert radians to degrees

grad2deg

grad2deg(<num>) - convert gradians to degrees

deg2grad

deg2grad(<num>) - convert degrees to gradians

rad2grad

rad2grad(<num>) - convert radians to gradians

Digest functions

md5

md5(<str>) - calculate the hex string representing the 16 byte md5 digest of the argument string.

sha1

sha1(<str>) - calculate the hex string representing the 20 byte SHA1 digest of the argument string.

hmac_sha1

hmac_sha1(<str>, <key>) - calculate the hmac signature of a string with a key, encoded as a binary string.

hmac_sha1_hex

hmac_sha1_hex(<str>, <key>) - calculate the hmac signature of a string with a key, encoded as a hex string.

hmac_sha1_base64

hmac_sha1_base64(<str>, <key>) - calculate the hmac signature of a string with a key, encoded as base64.

hmac_sha256

hmac_sha256(<str>, <key>) - calculate the hmac signature of a string with a key, encoded as a binary string.

hmac_sha256_hex

hmac_sha256_hex(<str>, <key>) - calculate the hmac signature of a string with a key, encoded as a hex string.

hmac_sha256_base64

hmac_sha256_base64(<str>, <key>) - calculate the hmac signature of a string with a key, encoded as base64.

Trigonometry

Trig functions expect radians as arguments unless otherwise noted

Basic Trig

tan(<num>) - calculate the tangent of <num>

sin(<num>) - calculate the sine of <num>

cos(<num>) - calculate the cosine of <num>

Trig Co-functions

cot(<num>) - calculate the co-tangent of <num>

sec(<num>) - calculate the secant of <num>

csc(<num>) - calculate the co-secant of <num>

Arcus functions

atan(<num>) - calculate the arctangent of <num>

asin(<num>) - calculate the arcsine of <num>

acos(<num>) - calculate the arccosine of <num>

Arcus Co-functions

acot(<num>) - calculate the arc co-tangent of <num>

asec(<num>) - calculate the arc secant of <num>

acsc(<num>) - calculate the arc co-secant of <num>

Hyperbolic functions

tanh(<num>) - calculate the hyperbolic tangent of <num>

sinh(<num>) - calculate the hyperbolic sine of <num>

cosh(<num>) - calculate the hyperbolic cosine of <num>

Hyperbolic Co-functions

coth(<num>) - calculate the hyperbolic co-tangent of <num>

sech(<num>) - calculate the hyperbolic secant of <num>

csch(<num>) - calculate the hyperbolic co-secant of <num>

Inverse functions

atanh(<num>) - calculate the hyperbolic arc tangent of <num>

asinh(<num>) - calculate the hyperbolic arc sine of <num>

cosh(<num>) - calculate the hyperbolic arc cosine of <num>

acoth(<num>) - calculate the hyperbolic arc co-tangent of <num>

asech(<num>) - calculate the hyperbolic arc secant of <num>

acsch(<num>) - calculate the hyperbolic arc co-secant of <num>

Great Circle Calculations

Great Circle Calculations are based upon a mathematical model, not geographical. Geographically, the zero axis for Latitude is located on the equator. The mathematical model places the zero axis for Latitude at the north pole.

The practical result of this model is that for geographical co-ordinates, the radian expression of the latitude must be subtracted from π/2. This will be demonstrated in the examples that follow the function definitions.

Distance

great_circle_distance(<long0>, π/2 - <lat0>, <long1>, π/2 - <lat1> |, r) - compute the distance along a great circle given two points on a spherical surface. r is an optional parameter for the radius of the sphere. If left unspecified, r defaults to 1-the unit sphere-and is expressed in radians.

Direction

great_circle_direction(<long0>, π/2 - <lat0>, <long1>, π/2 - <lat1>) - compute the direction of the great circle that connects the two points note: the direction is not static. It changes for each position along the great circle. Thus, the great circle direction is also referred to as a bearing

Mid Point

great_circle_midpoint(<long0>, π/2 - <lat0>, <long1>, π/2 - <lat1>) - compute the co-ordinates along the great circle that lay at the midpoint of two points

Way Point

great_circle_waypoint(<long0>, π/2 - <lat0>, <long1>, π/2 - <lat1>,<f>) - compute the co-ordinates along the great circle that lay at fraction f of the distance between points