package math
The math
package contains classes, traits and objects for common mathematical
operations. Its package object defines exponentiation, logarithmic, trigonometric,
etc. operators and functions.
- Alphabetic
- By Inheritance
- math
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
case class
Complex(re: Double, im: Double = 0.0) extends Fractional[Complex] with Ordered[Complex] with Product with Serializable
The
Complex
class is used to represent and operate on complex numbers.The
Complex
class is used to represent and operate on complex numbers. Internally, a complex number is represented as two double precision floating point numbers (Double). Externally, two forms are supported:a+bi = 2.1+3.2i via: Complex ("2.1+3.2i"), 'toString' (a, b) = (2.1, 3.2) via: create ("(2.1, 3.2)"), 'toString2'
Note: 'i * i = -1'. -------------------------------------------------------------------------
- re
the real part (e.g., 2.1)
- im
the imaginary part (e.g., 3.2)
-
final
class
Double_Exp extends AnyVal
The
Double_Exp
value class adds an exponentiation operator 'x ~ y' and a 'near_eq' operator 'x =~ y' toDouble
. The '~' has higher precedence than '*' or '/'. -
type
FunctionS2S = (Double) ⇒ Double
The type definition for a function of a scalar (f: Double => Double)
The type definition for a function of a scalar (f: Double => Double)
- See also
also
scalation.linalgebra
-
type
Functions = Array[FunctionS2S]
The type definition for an array of scalar functions
-
final
class
Int_Exp extends AnyVal
The
Int_Exp
value class adds an exponentiation operator 'x ~ y' and a 'near_eq' operator 'x =~ y' toInt
. The '~' has higher precedence than '*' or '/'. -
final
class
Long_Exp extends AnyVal
The
Long_Exp
value class adds an exponentiation operator 'x ~ y' and a 'near_eq' operator 'x =~ y' toLong
. The '~' has higher precedence than '*' or '/'. -
case class
ProbNum(x: Double, p: Double = 1.0) extends Numeric[ProbNum] with Ordered[ProbNum] with Error with Product with Serializable
The
ProbNum
class is used to represent probabilistic numbers '(x, p)' where 'x' is a real number and 'p' is its probability of occurrence.The
ProbNum
class is used to represent probabilistic numbers '(x, p)' where 'x' is a real number and 'p' is its probability of occurrence. FIX: Currently this class is half-baked!!!- x
the real number (double precision)
- p
the probability of its occurrence [0, 1]
- See also
http://okmij.org/ftp/Computation/monads.html#random-var-monad
-
case class
Rational(num: Long, den: Long = 1L) extends Fractional[Rational] with Ordered[Rational] with Product with Serializable
The
Rational
class is used to represent and operate on rational numbers.The
Rational
class is used to represent and operate on rational numbers. Internally, a rational number is represented as two long integers. Externally, two forms are supported:a/b = 2/3 via: Rational ("2/3"), 'toString' (a, b) = (2, 3) via: create ("(2, 3)") 'toString2'
Rational number can be created without loss of precision using the constructor, 'apply', 'create' or 'fromBigDecimal' methods. Other methods may lose precision.
- num
the numerator (e.g., 2)
- den
the denominator (e.g., 3)
-
case class
Real(hi: Double, lo: Double = 0.0) extends Fractional[Real] with Ordered[Real] with Product with Serializable
The
Real
class provides higher precision floating point numbers using the Double Double technique, which supports 106 bits of precision.The
Real
class provides higher precision floating point numbers using the Double Double technique, which supports 106 bits of precision. ----------------------------------------------------------------------------- Code adapted from DoubleDouble.java:- hi
the high portion of the real number
- lo
the low portion of the real number
- See also
http://tsusiatsoftware.net/dd/main.html
oai.cwi.nl/oai/asset/9159/9159A.pdf -----------------------------------------------------------------------------
Value Members
-
val
THRES: Double
The threshold used for near equality
-
def
cot(x: Double): Double
Return the cotangent of 'x'
-
def
csc(x: Double): Double
Return the cosecant of 'x'
-
implicit
def
double_exp(x: Double): Double_Exp
Implicit conversion from 'Double' to 'Double_Exp', which supports exponentiation and nearly equals.
Implicit conversion from 'Double' to 'Double_Exp', which supports exponentiation and nearly equals.
- x
the base parameter
-
implicit
def
int_exp(x: Int): Int_Exp
Implicit conversion from 'Int' to 'Int_Exp', which supports exponentiation and nearly equals.
Implicit conversion from 'Int' to 'Int_Exp', which supports exponentiation and nearly equals.
- x
the base parameter
-
def
log2(x: Double): Double
Compute the log of 'x' base 2.
Compute the log of 'x' base 2.
- x
the value whose log is sought
-
val
log_10: Double
The natural log of 10
-
val
log_2: Double
The natural log of 2
-
def
logb(b: Double, x: Double): Double
Compute the log of 'x' base 'b'.
Compute the log of 'x' base 'b'.
- b
the base of the logarithm
- x
the value whose log is sought
-
implicit
def
long_exp(x: Long): Long_Exp
Implicit conversion from 'Long' to 'Long_Exp', which supports exponentiation and nearly equals.
Implicit conversion from 'Long' to 'Long_Exp', which supports exponentiation and nearly equals.
- x
the base parameter
-
def
near_eq(x: Double, y: Double): Boolean
Determine whether two double precision floating point numbers 'x' and 'y' are nearly equal.
Determine whether two double precision floating point numbers 'x' and 'y' are nearly equal. Two numbers are considered to be nearly equal, if within '2 EPSILON'. A number is considered to be nearly zero, if within '2 MIN_NORMAL'. To accommodate round-off errors, may use 'TOL' instead of 'EPSILON'. --------------------------------------------------------------------------
- x
the first double precision floating point number
- y
the second double precision floating point number
- See also
BasicTest
stackoverflow.com/questions/4915462/how-should-i-do-floating-point-comparison -------------------------------------------------------------------------- If both 'x' and 'y' are NaN (Not-a-Number), the IEEE standard indicates that should be considered always not equal. For 'near_eq', they are considered nearly equal. Comment out the first line below to conform more closely to the IEEE standard.
http://stackoverflow.com/questions/10034149/why-is-nan-not-equal-to-nan --------------------------------------------------------------------------
-
def
nexp(x: Double): Double
Negative exponential function (e to the minus 'x').
Negative exponential function (e to the minus 'x').
- x
the argument of the function
-
val
noComplex: Complex
Missing value representation (use null if available, otherwise most negative value)
- val noDouble: Double
- val noInt: Int
- val noLong: Long
- val noRational: Rational
- val noReal: Real
- val noStrNum: StrNum
- val noTimeNum: TimeNum
-
def
oneIf(cond: Boolean): Int
Return 1 if condition 'cond' is true, else 0.
Return 1 if condition 'cond' is true, else 0.
- cond
the condition to evaluate
-
def
pow(x: Long, y: Long): Long
Power function for scala Longs 'x ~^ y'. Compute: 'math.pow (x, y).toLong' without using floating point, so as to not lose precision.
Power function for scala Longs 'x ~^ y'. Compute: 'math.pow (x, y).toLong' without using floating point, so as to not lose precision.
- x
the Long base parameter
- y
the Long exponent parameter
-
def
recip(x: Double): Double
Compute the reciprocal/inverse of 'x'.
Compute the reciprocal/inverse of 'x'.
- x
the number to invert
-
def
root(x: Long, y: Long): Long
Find the 'y'-th root of 'x', i.e., 'x ~ 1/y' for scala Longs. 'r = x ~ 1/y' is largest long integer 'r' such that 'r ~^ y <= x'.
Find the 'y'-th root of 'x', i.e., 'x ~ 1/y' for scala Longs. 'r = x ~ 1/y' is largest long integer 'r' such that 'r ~^ y <= x'.
- x
the Long base parameter
- y
the Long root level (reciprocal exponent) parameter
- See also
http://en.wikipedia.org/wiki/Shifting_nth_root_algorithm
http://stackoverflow.com/questions/8826822/calculate-nth-root-with-integer-arithmetic
-
def
roundTo(x: Double, places: Int = 4): Double
Round the given double to the desired number of decimal places.
Round the given double to the desired number of decimal places.
- x
the double number which needs to be rounded off
- places
the desired number of decimal places
-
def
sec(x: Double): Double
Return the secant of 'x'
-
def
sign(x: Double, y: Double): Double
Return the absolute value of 'x' with the sign of 'y'.
Return the absolute value of 'x' with the sign of 'y'.
- x
the value contributor
- y
the sign contributor
-
def
sq(x: Double): Double
Compute the square of 'x'.
Compute the square of 'x'.
- x
the number to sqaure
-
object
Combinatorics extends Error
The
Combinatorics
object provides several common combinatorics functions, such as factorial permutations, combinations, gamma and beta functions. -
object
CombinatoricsTest extends App
The
CombinatoricsTest
object tests the methods in theCombinatorics
object. -
object
CombinatoricsTest2 extends App
The
CombinatoricsTest2
object tests the Gamma and factorial methods in theCombinatorics
object. -
object
Complex extends Serializable
The
Complex
companion object defines the origin (zero) and the fourth roots of unity as well as some utility functions. -
object
ComplexTest extends App
The
ComplexTest
object is used to test theComplex
class.The
ComplexTest
object is used to test theComplex
class. > runMain scalation.math.ComplexTest -
object
ExtensionTest extends App
The
ExtensionTest
object is used to test theInt_Exp
,Long_Exp
andDouble_Exp
classes.The
ExtensionTest
object is used to test theInt_Exp
,Long_Exp
andDouble_Exp
classes. > runMain scalation.math.ExtensionTest -
object
ExtremeD
The
ExtremeD
object contains constants representing extreme values for Double (IEEE 754 double precision floating point numbers).The
ExtremeD
object contains constants representing extreme values for Double (IEEE 754 double precision floating point numbers).- See also
http://docs.oracle.com/javase/8/docs/api/java/lang/Double.html
en.wikipedia.org/wiki/Double-precision_floating-point_format ------------------------------------------------------------------------------ 64 bits: 1 sign-bit, 11 exponent-bits, 52 mantissa-bits + 1 implicit
-
object
ExtremeDTest extends App
The
ExtremeDTest
object is used to test theExtremeD
class.The
ExtremeDTest
object is used to test theExtremeD
class. > runMain scalation.math.ExtremeDTest -
object
MathTest extends App
The
MathTest
object is used to test the supplemental power, root, exponential, sign, indicator, logarithmic and trigonmetric functions defined in the 'scalation.math' package object.The
MathTest
object is used to test the supplemental power, root, exponential, sign, indicator, logarithmic and trigonmetric functions defined in the 'scalation.math' package object. > runMain scalation.math.MathTest -
object
Primes
The
Primes
object provides an array of 1000 prime numbers as well as methods to generate prime numbers within a given range. -
object
PrimesTest extends App
The
PrimesTest
object is use to perform timing test on thePrimes
object. -
object
PrimitiveType
The
PrimitiveType
object provides comparison operators forVec
elements.The
PrimitiveType
object provides comparison operators forVec
elements.- See also
Vec_Elem
-
object
ProbNumTest extends App
The
ProbNumTest
object is used to test theProbNum
class.The
ProbNumTest
object is used to test theProbNum
class. > runMain scalation.math.ProbNumTest -
object
Rational extends Serializable
The
Rational
companion object defines the origin (zero), one and minus one as well as some utility functions. -
object
RationalTest extends App
The
RationalTest
object is used to test theRational
class. -
object
Real extends Serializable
The
Real
companion object defines the origin (zero), one half and one as well as some utility functions. -
object
RealTest extends App
The
RealTest
object is used to test theReal
class.The
RealTest
object is used to test theReal
class. > runMain scalation.math.RealTest -
object
StrNumTest extends App
The
StrNumTest
object is used to test theStrNum
class.The
StrNumTest
object is used to test theStrNum
class. > runMain scalation.math.StrNumTest -
object
StrO extends Error
The
StrO
object is used to represent and operate on string numbers.The
StrO
object is used to represent and operate on string numbers. It contains an implicit class definition forStrNum
, which extends strings withNumeric
operations, it it can be used inVectorS
. The semantics ofStrNum
operators are similar those in Pike.- See also
http://docs.roxen.com/pike/7.0/tutorial/strings/operators.xml
-
object
TimeNumTest extends App
The
TimeNumTest
object is used to test theTimeNum
class.The
TimeNumTest
object is used to test theTimeNum
class. > runMain scalation.math.TimeNumTest -
object
TimeNumTest2 extends App
The
TimeNumTest2
object is used to test theTimeNum
class regarding approximately equal date-times.The
TimeNumTest2
object is used to test theTimeNum
class regarding approximately equal date-times. > runMain scalation.math.TimeNumTest2 -
object
TimeNumTest3 extends App
The
TimeNumTest3
object is used to test theTimeNum
class regarding its getChrono method.The
TimeNumTest3
object is used to test theTimeNum
class regarding its getChrono method. FIX - crashes - format exception > runMain scalation.math.TimeNumTest3 -
object
TimeO
The
TimeO
object is used to represent and operate on date-time values.The
TimeO
object is used to represent and operate on date-time values. It contains an implicit class definition forTimeNum
, which extendsInstant
withNumeric
operations that can be used inVectorT
. Thejava.time.Instant
class stores nano-seconds since the UNIX Epoch using along
for seconds andint
for nano-seconds (12 bytes or 96 bits). Thejava.time.ZonedDateTime
class is used with it to handle various date-time formats.