//ERDDAP/com.cohort.util/ScriptMath2
ScriptMath2
[JVM]
open class ScriptMath2
This class makes almost all of the static methods in com.cohort.Math2 accessible to JexlScript scripts as "Math2.name()" methods. This doesn't include the memory related and sleep related methods.
The underlying Math2 class is Copyright (c) 2005 Robert Simons (CoHortSoftware@gmail.com). See the MIT/X-like license in com/cohort/util/LICENSE.txt.
Author
Bob Simons (was bob.simons@noaa.gov, now BobSimons2.00@gmail.com) 2019-11-14
Constructors
ScriptMath2 | [JVM] constructor() |
Properties
Name | Summary |
---|---|
Binary0 | [JVM] val Binary0: Int = -2000 -2000 |
BinaryLimit | [JVM] val BinaryLimit: Int = 980 980; //2^980 = ~1e295 |
BytesPerGB | [JVM] val BytesPerGB: Long = 1073741824 BytesPerMB * (long)BytesPerKB |
BytesPerKB | [JVM] val BytesPerKB: Int = 1024 1024 |
BytesPerMB | [JVM] val BytesPerMB: Int = 1048576 BytesPerKB * BytesPerKB |
BytesPerPB | [JVM] val BytesPerPB: Long = 1125899906842624 BytesPerTB * BytesPerKB; |
BytesPerTB | [JVM] val BytesPerTB: Long = 1099511627776 BytesPerGB * BytesPerKB |
COMMON_MV9 | [JVM] val COMMON_MV9: Array<Double> -99, -99.9, -99.99, -999, -999.9, -9999, -99999, -999999, -9999999, 99, 99.9, 99.99, 999, 999. |
dEps | [JVM] val dEps: Double = 1.0E-13 epsilon suitable for doubles = 1e-13. |
fEps | [JVM] val fEps: Float = 1.0E-5f Eps values define small values that are suitable for quick tests if the difference between two values is close to the precision of of the data type. |
InverseTen | [JVM] val InverseTen: Array<Double> This defines inverse powers of ten. |
kelvinToC | [JVM] val kelvinToC: Double = -273.15 -273. |
kmPerMile | [JVM] val kmPerMile: Double = 1.6134453781512605 mPerMile * 0. |
ln10 | [JVM] val ln10: Double Math.log(10.0); //2. |
ln2 | [JVM] val ln2: Double Math.log(2. |
loAnd | [JVM] val loAnd: Long = 4294967295 ((long) Integer. |
meterPerFoot | [JVM] val meterPerFoot: Double = 0.30557677616501144 1200.0 / 3927.0. |
mPerMile | [JVM] val mPerMile: Double = 1613.4453781512605 5280 * meterPerFoot |
OneRadian | [JVM] val OneRadian: Double = 57.29577951308232 180.0 / Math. |
Ten | [JVM] val Ten: Array<Double> This defines powers of ten. |
Two | [JVM] val Two: Array<Int> two defines powers of two, e.g., Two[0]=1, Two[1]=2, Two[2]=4, ... |
TwoPi | [JVM] val TwoPi: Double = 6.283185307179586 2 * Math. |
UBYTE_MAX_VALUE | [JVM] val UBYTE_MAX_VALUE: Short = 255 255 |
UINT_MAX_VALUE | [JVM] val UINT_MAX_VALUE: Long = 4294967295 4294967295L |
ULONG_MAX_VALUE | [JVM] val ULONG_MAX_VALUE: BigInteger 18446744073709551615. |
USHORT_MAX_VALUE | [JVM] val USHORT_MAX_VALUE: Int = 65535 65535 |
Functions
Name | Summary |
---|---|
almost0 | [JVM] fun almost0(d: Double): Boolean This quickly tests if d is almost 0 (Math. |
almostEqual | [JVM] open fun almostEqual(nSignificantDigits: Int, d1: Double, d2: Double): Boolean This tests if the numbers are equal to at least n significant digits. [JVM] open fun almostEqual(nSignificantDigits: Int, f1: Float, f2: Float): Boolean This tests if two floats are equal to at least n significant digits. |
angle02Pi | [JVM] fun angle02Pi(radians: Double): Double This converts an angle (in radians) into the range >=0 to <2PI. |
angle0360 | [JVM] fun angle0360(degrees: Double): Double This converts an angle (in degrees) into the range >=0 to <360. |
anglePM180 | [JVM] fun anglePM180(degrees: Double): Double This converts an angle (in degrees) into the range >=-180 to <180 (180 becomes -180). |
bigger | [JVM] open fun bigger(d: Double): Double This increases the value (nicely). |
bigger15 | [JVM] open fun bigger15(d: Double): Double This increases the value (nicely) so the mantissa is 1 or 5. |
biggerAngle | [JVM] open fun biggerAngle(d: Double): Double This increases the double degrees value (nicely), and returns it as a string. |
biggerDouble | [JVM] open fun biggerDouble(def: Double, mult: Double, max: Double, d: Double): Double This increases d to the next multiple of mult. |
binaryExponent | [JVM] open fun binaryExponent(d: Double): Int This returns the binary exponent of a double: usually +-1023. |
binaryFindClosest | [JVM] open fun binaryFindClosest(dar: Array<Double>, x: Double): Int Find the closest element to x in an ascending sorted array. |
binaryFindFirstGAE | [JVM] open fun binaryFindFirstGAE(dar: Array<Double>, x: Double, precision: Int): Int Find the first element which is >x or almostEqual(precision, x) in an ascending sorted array. |
binaryFindFirstGE | [JVM] open fun binaryFindFirstGE(dar: Array<Double>, x: Double): Int Find the first element which is >= x in an ascending sorted array. |
binaryFindLastLAE | [JVM] open fun binaryFindLastLAE(dar: Array<Double>, x: Double, precision: Int): Int Find the last element which is <x or almostEqual(5, x) in an ascending sorted array. |
binaryFindLastLE | [JVM] open fun binaryFindLastLE(dar: Array<Double>, x: Double): Int Find the last element which is <= x in an ascending sorted array. |
byteToChar | [JVM] fun byteToChar(b: Int): Char Safely converts a byte (-128..127) to char (0..255). |
compassToMathDegrees | [JVM] fun compassToMathDegrees(compass: Double): Double This converts a compass heading (usually 0..360, where North is 0, East is 90...) to Math-style degrees (East is 0, North is 90, ...). |
doubleToFloatNaN | [JVM] fun doubleToFloatNaN(d: Double): Float Safely converts a double to a float (including the non-standard conversion of large values to Float.NaN, not Float.POSITIVE_INFINITY). |
equalsIncludingNanOrInfinite | [JVM] open fun equalsIncludingNanOrInfinite(a: Double, b: Double): Boolean open fun equalsIncludingNanOrInfinite(a: Float, b: Float): Boolean This returns true if a == b. |
exponent | [JVM] open fun exponent(d: Double): Double This returns the double exponent of a double (e.g., -0.0175 returns 0.01 since -0.0175=-1.75*0.01). |
finiteMax | [JVM] open fun finiteMax(a: Double, b: Double): Double This returns the greater value. |
finiteMin | [JVM] open fun finiteMin(a: Double, b: Double): Double This returns the lesser value. |
floatToDouble | [JVM] fun floatToDouble(f: Double): Double Safely converts a float to a double. |
floatToDoubleNaN | [JVM] fun floatToDoubleNaN(f: Double): Double Crudely (not nicely) converts a float to a double (including the non-standard conversion of INFINITY values to NaN). |
floorDiv | [JVM] open fun floorDiv(num: Int, den: Int): Int open fun floorDiv(num: Long, den: Long): Long A div where the implied mod is always >=0. |
frac | [JVM] open fun frac(d: Double): Double This returns the fraction part of a double. |
gcd | [JVM] open fun gcd(n: Int, d: Int): Int Finds the greatest common divisor. |
getSmallIncrement | [JVM] open fun getSmallIncrement(range: Double): Double This returns a small increment roughly 1/100th the range (e.g., .1, 1, 10, ....). |
greaterThanAE | [JVM] open fun greaterThanAE(nSignificantDigits: Int, d1: Double, d2: Double): Boolean This tests if d1 is greater than or almostEqual9 d2. |
guessFrac | [JVM] open fun guessFrac(r: Double, int3: Array<Int>) Looks for a fraction very close to some decimal value. |
guessFracString | [JVM] open fun guessFracString(d: Double): String This creates a String based on the results of guessFrac() |
hiDiv | [JVM] open fun hiDiv(num: Int, den: Int): Int open fun hiDiv(num: Long, den: Long): Long A div that rounds up if den>0. |
intExponent | [JVM] open fun intExponent(d: Double): Int This returns the integer exponent of a double (-0.0175 returns -2 since -0.0175=-1.75*10^-2). |
lessThanAE | [JVM] open fun lessThanAE(nSignificantDigits: Int, d1: Double, d2: Double): Boolean This tests if d1 is less than or almostEqual d2. |
longToDoubleNaN | [JVM] fun longToDoubleNaN(tl: Long): Double This converts a long to a double (Long.MAX_VALUE becomes NaN). |
looserAngle0360 | [JVM] fun looserAngle0360(degrees: Double): Double This converts an angle (in degrees) into the range >= 0 to <=360 (note 360 is valid). |
looserAnglePM180 | [JVM] fun looserAnglePM180(degrees: Double): Double This converts an angle (in degrees) into the range >=-180 to <=180 (note 180 is valid). |
mantissa | [JVM] open fun mantissa(d: Double): Double This returns the mantissa of a double (-0.0175 returns -1.75 since -0.0175=-1.75*10^-2). |
mathToCompassDegrees | [JVM] fun mathToCompassDegrees(math: Double): Double This converts a Math-style degrees (East is 0, North is 90, ...) to a compass heading (where North is 0, East is 90, ...). |
minMax | [JVM] fun minMax(min: Double, max: Double, current: Double): Double This forces a double into a range defined by min..max. [JVM] fun minMax(min: Int, max: Int, current: Int): Int This forces a int into a range defined by min..max. |
minMaxDef | [JVM] fun minMaxDef(min: Double, max: Double, def: Double, current: Double): Double This forces a double into a range defined by min..max. [JVM] fun minMaxDef(min: Int, max: Int, def: Int, current: Int): Int This forces an int into a range defined by min..max. |
NaNCheck | [JVM] open fun NaNCheck(d: Double): Double Checks if the value is NaN or infinite: returns Double.NaN if so; otherwise returns the original value. |
narrowToByte | [JVM] fun narrowToByte(i: Int): Byte Safely narrows an int to a byte. [JVM] fun narrowToByte(i: Long): Byte Safely narrows a long to a byte. |
narrowToChar | [JVM] fun narrowToChar(i: Int): Char Safely narrows an int to a char. [JVM] fun narrowToChar(i: Long): Char Safely narrows a long to a char. |
narrowToInt | [JVM] fun narrowToInt(i: Long): Int Safely narrows a long to an int. |
narrowToShort | [JVM] fun narrowToShort(i: Int): Short Safely narrows an int to a short. [JVM] fun narrowToShort(i: Long): Short Safely narrows a long to a short. |
niceDouble | [JVM] fun niceDouble(d: Double, nDigits: Int): Double Safely tries to un-bruise a double (8. |
odd | [JVM] open fun odd(i: Int): Boolean Indicates if i is odd. |
oneDigitBigger | [JVM] open fun oneDigitBigger(max: Double, def: Double, d: Double): Double This increases the first digit of d (for example, .8, .9, 1, 2, 3, ..., 9, 10, 20, 30, ...). |
oneDigitSmaller | [JVM] open fun oneDigitSmaller(min: Double, def: Double, d: Double): Double This decreases the first digit of d (for example, 30, 20, 10, 9, ..., 3, 2, 1, .9, .8, ...). |
random | [JVM] open fun random(max: Int): Int This returns a random integer between 0 and max-1. |
reduceHashCode | [JVM] open fun reduceHashCode(hashCode: Int): String This reduces a hash code (currently to a 10 digit unsigned number -- no loss of information). |
roundDiv | [JVM] open fun roundDiv(num: Int, den: Int): Int A div that rounds. |
roundTo | [JVM] fun roundTo(d: Double, nPlaces: Int): Double Rounds the value to the specified number of decimal places. |
roundToByte | [JVM] fun roundToByte(d: Double): Byte Safely rounds a double to a byte. |
roundToChar | [JVM] fun roundToChar(d: Double): Char Safely rounds a double to a char (treated as unsigned short). |
roundToDouble | [JVM] fun roundToDouble(d: Double): Double Safely rounds a double to the nearest integer (stored as a double). |
roundToInt | [JVM] fun roundToInt(d: Double): Int Safely rounds a double to an int. |
roundToLong | [JVM] fun roundToLong(d: Double): Long Safely rounds a double to a long. |
roundToShort | [JVM] fun roundToShort(d: Double): Short Safely rounds a double to a short. |
roundToUByte | [JVM] fun roundToUByte(d: Double): Short Safely rounds a double to a ubyte. |
roundToUInt | [JVM] fun roundToUInt(d: Double): Long Safely rounds a double to a uint. |
roundToULong | [JVM] fun roundToULong(d: Double): BigInteger Safely rounds a double to a ulong. |
roundToUShort | [JVM] fun roundToUShort(d: Double): Int Safely rounds a double to a ushort. |
setSeed | [JVM] open fun setSeed(seed: Long) This sets the seed for the next call to random(). |
sign1 | [JVM] open fun sign1(i: Int): Int This returns 1 for positive i's, -1 for negative i's, and 1 if i is 0 (i.e., 0 is treated as a positive number). |
smaller | [JVM] open fun smaller(d: Double): Double This decreases the value (nicely). |
smaller15 | [JVM] open fun smaller15(d: Double): Double This gets the double value from the string, decreases it (nicely), so the mantissa is 1 or 5. |
smallerAngle | [JVM] open fun smallerAngle(d: Double): Double This decreases the double degree value (nicely). |
smallerDouble | [JVM] open fun smallerDouble(def: Double, mult: Double, min: Double, d: Double): Double This decreases d to the previous multiple of mult. |
suggestDivisions | [JVM] open fun suggestDivisions(range: Double): Array<Double> This suggests the division distance along an axis so that there will be about 5-7 primary divisions and 10-25 secondary. |
suggestLowHigh | [JVM] open fun suggestLowHigh(low: Double, high: Double): Array<Double> This returns a nice bounding range (e.g., for an axis) which includes low and high. |
suggestMaxDivisions | [JVM] open fun suggestMaxDivisions(range: Double, maxDivisions: Int): Double This suggests the division distance along an axis so that there will be between maxDivisions/2 and maxDivisions. |
ten | [JVM] open fun ten(toThe: Int): Double This returns an integer power of ten. |
trunc | [JVM] open fun trunc(d: Double): Double This returns the truncated part of a double. |
truncToInt | [JVM] open fun truncToInt(d: Double): Int This returns the truncated part of a double, stored as an int. |
ulongToDouble | [JVM] fun ulongToDouble(tl: Long): Double This converts an unsigned long to a double. |
unsignedByte | [JVM] fun unsignedByte(b: Int): Int Safely converts a signed byte (-128..127) to an unsigned byte (0..255). |