base64encode(<str>)
- returns a Base64-encoded string
base64decode(<str>)
- returns a Base64-decoded string
hashFunctions()
- returns the array of supported hash function names (strings) supported by the current Node engine
hash(
- uses the method specified by the <hashFn>,
)<toHash>
name to return the hashed hashFn
stringtoHash
Everything after this note is not supported at this time. |
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.
exp(<num>)
- return e (natural logrithm) raised to the <num>th power
n = math:exp(2); |
int(<num>)
- the integer value of <num>
n = math:int(2.999); |
Only numbers are valid arguments to int
. To coerce a string, use the Universal operator as().
abs(<num>)
- absolute value of <num>
n = math:abs(-12); |
log(<num>)
- natural log of <num>
n = math:log(2); |
sqrt(<num>)
- square root of <num>
n = math:sqrt(2); |
power(<num1>,<num1>)
- <num1> to the <num2>th power.
n = math:power(2,3); // n = 8 |
ceiling(<num>)
- the smallest integer not less than <num>
n = math:ceiling(2.78); // n = 3 |
floor(<num>) - the largest integer not greater than <num>
n = math:floor(2.78); // n = 2 |
round(<num> - convert <num> to the nearest integer.
n = math:round(2.1); // n = 2 m = math:round(2.7); // n = 3 |
deg2rad(<num>)
- convert degrees to radians
r = math:deg2rad(d); |
grad2rad(<num>)
- convert gradians to radians
r = math:grad2rad(g); |
rad2deg(<num>)
- convert radians to degrees
d = math:rad2deg(r); |
grad2deg(<num>)
- convert gradians to degrees
d = math:grad2deg(g); |
deg2grad(<num>)
- convert degrees to gradians
g = math:deg2grad(d); |
rad2grad(<num>)
- convert radians to gradians
g = math:rad2grad(r); |
Based on the recommendations of NIST SP 800-131A, avoid MD5 where collision resistance is required, such as digital signatures. |
md5(<str>)
- calculate the hex string representing the 16 byte md5 digest of the argument string.
d = math:md5("Hello" + foo) |
Based on the recommendations of NIST SP 800-131A, avoid SHA-1 where collision resistance is required, such as digital signatures. |
sha1(<str>)
- calculate the hex string representing the 20 byte SHA1 digest of the argument string.
d = math:sha1("Hello" + foo) |
hmac_sha1(<str>, <key>)
- calculate the hmac signature of a string with a key, encoded as a binary string.
sig = math:hmac_sha1("Hello" + foo, "mykey") |
hmac_sha1_hex(<str>, <key>)
- calculate the hmac signature of a string with a key, encoded as a hex string.
sig = math:hmac_sha1_hex("Hello" + foo, "mykey") |
hmac_sha1_base64(<str>, <key>)
- calculate the hmac signature of a string with a key, encoded as base64.
sig = math:hmac_sha1_base64("Hello" + foo, "mykey") |
hmac_sha256(<str>, <key>)
- calculate the hmac signature of a string with a key, encoded as a binary string.
sig = math:hmac_sha256("Hello" + foo, "mykey") |
hmac_sha256_hex(<str>, <key>)
- calculate the hmac signature of a string with a key, encoded as a hex string.
sig = math:hmac_sha256_hex("Hello" + foo, "mykey") |
hmac_sha256_base64(<str>, <key>)
- calculate the hmac signature of a string with a key, encoded as base64.
sig = math:hmac_sha256_base64("Hello" + foo, "mykey") |
Trig functions expect radians as arguments unless otherwise noted
tan(<num>)
- calculate the tangent of <num>
d = math:tan(r) |
sin(<num>)
- calculate the sine of <num>
d = math:sin(r) |
cos(<num>)
- calculate the cosine of <num>
d = math:cos(r) |
cot(<num>)
- calculate the co-tangent of <num>
d = math:cot(r) |
sec(<num>)
- calculate the secant of <num>
d = math:sec(r) |
csc(<num>)
- calculate the co-secant of <num>
d = math:csc(r) |
atan(<num>)
- calculate the arctangent of <num>
d = math:atan(r) |
asin(<num>)
- calculate the arcsine of <num>
d = math:asin(r) |
acos(<num>)
- calculate the arccosine of <num>
d = math:acos(r) |
acot(<num>)
- calculate the arc co-tangent of <num>
d = math:acot(r) |
asec(<num>)
- calculate the arc secant of <num>
d = math:asec(r) |
acsc(<num>)
- calculate the arc co-secant of <num>
d = math:acsc(r) |
tanh(<num>)
- calculate the hyperbolic tangent of <num>
d = math:tanh(r) |
sinh(<num>)
- calculate the hyperbolic sine of <num>
d = math:sinh(r) |
cosh(<num>)
- calculate the hyperbolic cosine of <num>
d = math:cosh(r) |
coth(<num>)
- calculate the hyperbolic co-tangent of <num>
d = math:coth(r) |
sech(<num>)
- calculate the hyperbolic secant of <num>
d = math:sech(r) |
csch(<num>)
- calculate the hyperbolic co-secant of <num>
d = math:csch(r) |
atanh(<num>)
- calculate the hyperbolic arc tangent of <num>
d = math:atanh(r) |
asinh(<num>)
- calculate the hyperbolic arc sine of <num>
d = math:asinh(r) |
cosh(<num>)
- calculate the hyperbolic arc cosine of <num>
d = math:acosh(r) |
acoth(<num>)
- calculate the hyperbolic arc co-tangent of <num>
d = math:acoth(r) |
asech(<num>)
- calculate the hyperbolic arc secant of <num>
d = math:asech(r) |
acsch(<num>)
- calculate the hyperbolic arc co-secant of <num>
d = math:acsch(r) |
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.
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.
r90 = math:pi()/2; rEk = 6378; // radius of the Earth in km // point a lata = 40.4267290; lnga = -111.9025358; // point b latb = 43.8310154; lngb = -111.7747790; // convert co-ordinates to radians rlata = math:deg2rad(lata); rlnga = math:deg2rad(lnga); rlatb = math:deg2rad(latb); rlngb = math:deg2rad(lngb); // distance between two co-ordinates in radians dR = math:great_circle_distance(rlnga,r90 - rlata, rlngb,r90 - rlatb); // distance between two co-ordinates in kilometers dE = math:great_circle_distance(rlnga,r90 - rlata, rlngb,r90 - rlatb, rEk); |
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
// using the same co-ordinates as the great distance example b = math:great_circle_direction(rlnga,r90 - rlata, rlngb,r90 - rlatb); |
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
// using the same co-ordinates as the great distance example b = math:great_circle_midpoint(rlnga,r90 - rlata, rlngb,r90 - rlatb); lng = b[0]; lat = b[1]; |
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
// using the same co-ordinates as the great distance example // find waypoint 3/4ths of the distance along the great circle b = math:great_circle_waypoint(rlnga,r90 - rlata, rlngb,r90 - rlatb,.75); lng = b[0]; lat = b[1]; |