spire.math

package spire.math

Type members

Classlikes

case
class Above[A] extends Interval[A]
@SerialVersionUID(1L)
final
class Algebraic extends ScalaNumber with ScalaNumericConversions with Serializable

Algebraic provides an exact number type for algebraic numbers. Algebraic numbers are roots of polynomials with rational coefficients. With it, we can represent expressions involving addition, multiplication, division, n-roots (eg. sqrt or cbrt), and roots of rational polynomials. So, it is similar Rational, but adds roots as a valid, exact operation. The cost is that this will not be as fast as Rational for many operations.

Algebraic provides an exact number type for algebraic numbers. Algebraic numbers are roots of polynomials with rational coefficients. With it, we can represent expressions involving addition, multiplication, division, n-roots (eg. sqrt or cbrt), and roots of rational polynomials. So, it is similar Rational, but adds roots as a valid, exact operation. The cost is that this will not be as fast as Rational for many operations.

In general, you can assume all operations on this number type are exact, except for those that explicitly construct approximations to an Algebraic number, such as toBigDecimal.

For an overview of the ideas, algorithms, and proofs of this number type, you can read the following papers:

  • "On Guaranteed Accuracy Computation." C. K. Yap.
  • "Recent Progress in Exact Geometric Computation." C. Li, S. Pion, and C. K. Yap.
  • "A New Constructive Root Bound for Algebraic Expressions" by C. Li & C. K. Yap.
  • "A Separation Bound for Real Algebraic Expressions." C. Burnikel, et al.
Companion
object
Companion
class
@SerialVersionUID(1L)
class AlgebraicAlgebra extends AlgebraicIsField with AlgebraicIsNRoot with AlgebraicIsReal with Serializable
case
class All[A] extends Interval[A]
case
class Below[A] extends Interval[A]
abstract

Abstract class that can be used to implement custom binary merges with e.g. special collision behavior or an ordering that is not defined via an Order[T] typeclass

Abstract class that can be used to implement custom binary merges with e.g. special collision behavior or an ordering that is not defined via an Order[T] typeclass

Companion
object
object BinaryMerge extends Merge

Merge that uses binary search to reduce the number of comparisons

Merge that uses binary search to reduce the number of comparisons

This can be orders of magnitude quicker than a linear merge for types that have a relatively expensive comparison operation (e.g. Rational, BigInt, tuples) and will not be much slower than linear merge even in the worst case for types that have a very fast comparison (e.g. Int)

Companion
class
trait BitString[@specialized(Byte, Short, Int, Long) A] extends Bool[A]
Companion
object
object BitString
Companion
class
case
class Bounded[A] extends Interval[A]
object Complex extends ComplexInstances
Companion
class
@SerialVersionUID(0L)
final case
class Complex[@specialized(Float, Double) T](real: T, imag: T) extends ScalaNumber with ScalaNumericConversions with Serializable

Complex numbers. Depending on the underlying scalar T, can represent the Gaussian integers (T = BigInt/SafeLong), the Gaussian rationals (T = Rational) or the complex number field (T: Field).

Complex numbers. Depending on the underlying scalar T, can represent the Gaussian integers (T = BigInt/SafeLong), the Gaussian rationals (T = Rational) or the complex number field (T: Field).

Note that we require T to be at least CRing, a commutative ring, so the implementation below is slightly less general than the Cayley-Dickson construction.

Companion
object
trait ConvertableFrom[@specialized A]
Companion
object
Companion
class
trait ConvertableTo[@specialized A]
Companion
object
Companion
class
case
class Empty[A] extends Interval[A]

FastComplex is an ugly, beautiful hack.

FastComplex is an ugly, beautiful hack.

The basic idea is to encode two 32-bit Floats into a single 64-bit Long. The lower-32 bits are the "real" Float and the upper-32 are the "imaginary" Float.

Since we're overloading the meaning of Long, all the operations have to be defined on the FastComplex object, meaning the syntax for using this is a bit ugly. To add to the ugly beauty of the whole thing I could imagine defining implicit operators on Long like +@, -@, *@, /@, etc.

You might wonder why it's even worth doing this. The answer is that when you need to allocate an array of e.g. 10-20 million complex numbers, the GC overhead of using any object is HUGE. Since we can't build our own "pass-by-value" types on the JVM we are stuck doing an encoding like this.

Here are some profiling numbers for summing an array of complex numbers, timed against a concrete case class implementation using Float (in ms):

size | encoded |  class
 1M |     5.1 |    5.8
 5M |    28.5 |   91.7
 10M |    67.7 |  828.1
 20M |   228.0 | 2687.0

Not bad, eh?

Companion
class
final
class FloatComplex(val u: Long) extends AnyVal

Value class which encodes two floating point values in a Long.

Value class which encodes two floating point values in a Long.

We get (basically) unboxed complex numbers using this hack. The underlying implementation lives in the FastComplex object.

Companion
object
trait Fractional[@specialized(Float, Double) A] extends Field[A] with NRoot[A] with Integral[A] with Order[A]
Companion
object
object Fractional
Companion
class
object InsertionSort extends Sort

An implementation of insertion sort.

An implementation of insertion sort.

Works well for small arrays but due to quadratic complexity is not generally optimal.

trait Integral[@specialized(Int, Long) A] extends EuclideanRing[A] with ConvertableFrom[A] with ConvertableTo[A] with IsReal[A] with Order[A]

Integral number types, where / is truncated division.

Integral number types, where / is truncated division.

Companion
object
object Integral
Companion
class
class IntegralOps[A](lhs: A)(implicit ev: Integral[A])
sealed abstract
class Interval[A] extends Serializable

Interval represents a set of values, usually numbers.

Interval represents a set of values, usually numbers.

Intervals have upper and lower bounds. Each bound can be one of four kinds:

  • Closed: The boundary value is included in the interval. * Open: The boundary value is excluded from the interval. * Unbound: There is no boundary value. * Empty: The interval itself is empty.

When the underlying type of the interval supports it, intervals may be used in arithmetic. There are several possible interpretations of interval arithmetic: the interval can represent uncertainty about a single value (for instance, a quantity +/- tolerance in engineering) or it can represent all values in the interval simultaneously. In this implementation we have chosen to use the probabillistic interpretation.

One common pitfall with interval arithmetic is that many familiar algebraic relations do not hold. For instance, given two intervals a and b:

a == b does not imply a * a == a * b

Consider a = b = [-1, 1]. Since any number times itself is non-negative, a * a = [0, 1]. However, a * b = [-1, 1], since we may actually have a=1 and b=-1.

These situations will result in loss of precision (in the form of wider intervals). The result is not wrong per se, but less accurate than it could be.

These intervals should not be used with floating point bounds, as proper rounding is not implemented. Generally, the JVM is not an easy platform to perform robust arithmetic, as the IEEE 754 rounding modes cannot be set.

Companion
object
object Interval
Companion
class
object Jet extends JetInstances

==Overview== A simple implementation of N-dimensional dual numbers, for automatically computing exact derivatives of functions. This code (and documentation) closely follow the one in Google's "Ceres" library of non-linear least-squares solvers (see Sameer Agarwal, Keir Mierle, and others: Ceres Solver.)

==Overview== A simple implementation of N-dimensional dual numbers, for automatically computing exact derivatives of functions. This code (and documentation) closely follow the one in Google's "Ceres" library of non-linear least-squares solvers (see Sameer Agarwal, Keir Mierle, and others: Ceres Solver.)

While a complete treatment of the mechanics of automatic differentiation is beyond the scope of this header (see http://en.wikipedia.org/wiki/Automatic_differentiation for details), the basic idea is to extend normal arithmetic with an extra element "h" such that h != 0, but h^2^ = 0. Dual numbers are extensions of the real numbers analogous to complex numbers: whereas complex numbers augment the reals by introducing an imaginary unit i such that i^2^ = -1, dual numbers introduce an "infinitesimal" unit h such that h^2^ = 0. Analogously to a complex number c = x + yi, a dual number d = x * yh has two components: the "real" component x, and an "infinitesimal" component y. Surprisingly, this leads to a convenient method for computing exact derivatives without needing to manipulate complicated symbolic expressions.

For example, consider the function

 f(x) = x * x ,

evaluated at 10. Using normal arithmetic,

f(10) = 100, and df/dx(10) = 20.

Next, augment 10 with an infinitesimal h to get:

 f(10 + h) = (10 + h) * (10 + h)
           = 100 + 2 * 10 * h + h * h
           = 100 + 20 * h       +---
                   +-----       |
                   |            +--- This is zero
                   |
                   +----------------- This is df/dx

Note that the derivative of f with respect to x is simply the infinitesimal component of the value of f(x + h). So, in order to take the derivative of any function, it is only necessary to replace the numeric "object" used in the function with one extended with infinitesimals. The class Jet, defined in this header, is one such example of this, where substitution is done with generics.

To handle derivatives of functions taking multiple arguments, different infinitesimals are used, one for each variable to take the derivative of. For example, consider a scalar function of two scalar parameters x and y:

 f(x, y) = x * x + x * y

Following the technique above, to compute the derivatives df/dx and df/dy for f(1, 3) involves doing two evaluations of f, the first time replacing x with x + h, the second time replacing y with y + h.

For df/dx:

 f(1 + h, y) = (1 + h) * (1 + h) + (1 + h) * 3
             = 1 + 2 * h + 3 + 3 * h
             = 4 + 5 * h

 Therefore df/dx = 5

For df/dy:

 f(1, 3 + h) = 1 * 1 + 1 * (3 + h)
             = 1 + 3 + h
             = 4 + h

 Therefore df/dy = 1

To take the gradient of f with the implementation of dual numbers ("jets") in this file, it is necessary to create a single jet type which has components for the derivative in x and y, and pass them to a routine computing function f. It is convenient to use a generic version of f, that can be called also with non-jet numbers for standard evaluation:

 def f[@specialized(Double) T : Field](x: T, y: T): T = x * x + x * y

 val xValue = 9.47892774
 val yValue = 0.287740

 // The "2" means there should be 2 dual number components.
 implicit val dimension = JetDim(2)
 val x: Jet[Double] = xValue + Jet.h[Double](0);  // Pick the 0th dual number for x.
 val y: Jet[Double] = yValue + Jet.h[Double](1);  // Pick the 1th dual number for y.

 val z: Jet[Double] = f(x, y);
 println("df/dx = " + z.infinitesimal(0) + ", df/dy = " + z.infinitesimal(1));

For the more mathematically inclined, this file implements first-order "jets". A 1st order jet is an element of the ring

 T[N] = T[t_1, ..., t_N] / (t_1, ..., t_N)^2

which essentially means that each jet consists of a "scalar" value 'a' from T and a 1st order perturbation vector 'v' of length N:

 x = a + \sum_i v[i] t_i

A shorthand is to write an element as x = a + u, where u is the perturbation. Then, the main point about the arithmetic of jets is that the product of perturbations is zero:

 (a + u) * (b + v) = ab + av + bu + uv
                   = ab + (av + bu) + 0

which is what operator* implements below. Addition is simpler:

 (a + u) + (b + v) = (a + b) + (u + v).

The only remaining question is how to evaluate the function of a jet, for which we use the chain rule:

 f(a + u) = f(a) + f'(a) u

where f'(a) is the (scalar) derivative of f at a.

By pushing these things through generics, we can write routines that at same time evaluate mathematical functions and compute their derivatives through automatic differentiation.

Companion
class
@SerialVersionUID(0L)
final case
class Jet[@specialized(Float, Double) T](real: T, infinitesimal: Array[T]) extends ScalaNumber with ScalaNumericConversions with Serializable
Companion
object
case
class JetDim(dimension: Int)

Used to implicitly define the dimensionality of the Jet space.

Used to implicitly define the dimensionality of the Jet space.

Value Params
dimension

the number of dimensions.

object LinearMerge extends Merge

Simple linear merge

Simple linear merge

trait Merge

Interface for a merging strategy object.

Interface for a merging strategy object.

object MergeSort extends Sort

In-place merge sort implementation. This sort is stable but does mutate the given array. It is an in-place sort but it does allocate a temporary array of the same size as the input. It uses InsertionSort for sorting very small arrays.

In-place merge sort implementation. This sort is stable but does mutate the given array. It is an in-place sort but it does allocate a temporary array of the same size as the input. It uses InsertionSort for sorting very small arrays.

@SerialVersionUID(0L)
sealed abstract
class Natural extends ScalaNumber with ScalaNumericConversions with Serializable
Companion
object
object Natural extends NaturalInstances
Companion
class
@SerialVersionUID(0L)
class NaturalAlgebra extends NaturalIsCRig with NaturalTruncatedDivision with Serializable
object Number extends NumberInstances

Convenient apply and implicits for Numbers

Convenient apply and implicits for Numbers

Companion
class
sealed
trait Number extends ScalaNumericConversions with Serializable
Companion
object
@SerialVersionUID(0L)
class NumberAlgebra extends NumberIsField with NumberIsNRoot with NumberIsTrig with NumberIsReal with Serializable
object NumberTag
Companion
class
trait NumberTag[A]

A NumberTag provides information about important implementations details of numbers. For instance, it includes information about whether we can expect arithmetic to overflow or produce invalid values, the bounds of the number if they exist, whether it is an approximate or exact number type, etc.

A NumberTag provides information about important implementations details of numbers. For instance, it includes information about whether we can expect arithmetic to overflow or produce invalid values, the bounds of the number if they exist, whether it is an approximate or exact number type, etc.

Companion
object
trait Numeric[@specialized(Int, Long, Float, Double) A] extends Ring[A] with AdditiveCommutativeGroup[A] with MultiplicativeCommutativeGroup[A] with NRoot[A] with ConvertableFrom[A] with ConvertableTo[A] with IsReal[A]

TODO

TODO

3. LiteralOps? Literal conversions?
4. Review operator symbols?
5. Support for more operators?
6. Start to worry about things like e.g. pow(BigInt, BigInt)
Companion
object
object Numeric
Companion
class
case
class Point[A] extends Interval[A]

Polynomial A univariate polynomial class and EuclideanRing extension trait for arithmetic operations. Polynomials can be instantiated using any type C for which a Ring[C] and Eq[C] are in scope, with exponents given by Int values. Some operations require more precise algebraic structures, such as GCDRing, EuclideanRing or Field to be in scope.

Polynomial A univariate polynomial class and EuclideanRing extension trait for arithmetic operations. Polynomials can be instantiated using any type C for which a Ring[C] and Eq[C] are in scope, with exponents given by Int values. Some operations require more precise algebraic structures, such as GCDRing, EuclideanRing or Field to be in scope.

Companion
class
trait Polynomial[@specialized(Double) C]
Companion
object
trait PolynomialEq[@specialized(Double) C] extends Eq[Polynomial[C]]
trait PolynomialOverCRing[@specialized(Double) C] extends CommutativeRing[Polynomial[C]] with PolynomialOverRing[C] with RingAssociativeAlgebra[Polynomial[C], C]
trait PolynomialOverField[@specialized(Double) C] extends PolynomialOverRing[C] with EuclideanRing[Polynomial[C]] with VectorSpace[Polynomial[C], C] with FieldAssociativeAlgebra[Polynomial[C], C]
trait PolynomialOverRig[@specialized(Double) C] extends PolynomialOverSemiring[C] with Rig[Polynomial[C]]
trait PolynomialOverRing[@specialized(Double) C] extends PolynomialOverRng[C] with Ring[Polynomial[C]]
trait PolynomialOverRng[@specialized(Double) C] extends PolynomialOverSemiring[C] with Rng[Polynomial[C]]
trait PolynomialOverSemiring[@specialized(Double) C] extends Semiring[Polynomial[C]]
Companion
class
final case
class Quaternion[@specialized(Float, Double) A](r: A, i: A, j: A, k: A) extends ScalaNumber with ScalaNumericConversions with Serializable

Quaternions defined over a subset A of the real numbers.

Quaternions defined over a subset A of the real numbers.

Companion
object
object QuickSort

In-place quicksort implementation. It is not stable, but does not allocate extra space (other than stack). Like MergeSort, it uses InsertionSort for sorting very small arrays.

In-place quicksort implementation. It is not stable, but does not allocate extra space (other than stack). Like MergeSort, it uses InsertionSort for sorting very small arrays.

sealed abstract
class Rational extends ScalaNumber with ScalaNumericConversions with Ordered[Rational]
Companion
object
Companion
class
@SerialVersionUID(1L)
class RationalAlgebra extends RationalIsField with RationalIsReal with Serializable
sealed
trait Real extends ScalaNumber with ScalaNumericConversions
Companion
object
object Real extends RealInstances
Companion
class
@SerialVersionUID(0L)
trait RealIsFractional extends Fractional[Real] with forCommutativeRing[Real] with Trig[Real] with Field[Real] with Order[Real]
sealed abstract
class SafeLong extends ScalaNumber with ScalaNumericConversions with Ordered[SafeLong]

Provides a type to do safe long arithmetic. This type will never overflow, but rather convert the underlying long to a BigInteger as need and back down to a Long when possible.

Provides a type to do safe long arithmetic. This type will never overflow, but rather convert the underlying long to a BigInteger as need and back down to a Long when possible.

Companion
object
Companion
class
trait ScalaOrderingWrapperCompat[A] extends Ordering[A]
object Searching
trait Select
trait SelectLike extends Select

Given a function for finding approximate medians, this will create an exact median finder.

Given a function for finding approximate medians, this will create an exact median finder.

object Selection
trait Sort

Interface for a sorting strategy object.

Interface for a sorting strategy object.

object Sorting

Object providing in-place sorting capability for arrays.

Object providing in-place sorting capability for arrays.

Sorting.sort() uses quickSort() by default (in-place, not stable, generally fastest but might hit bad cases where it is quadratic. Also provides mergeSort() (in-place, stable, uses extra memory, still pretty fast) and insertionSort(), which is slow except for small arrays.

final
class Trilean(val value: Int) extends AnyVal

Implementation of three-valued logic.

Implementation of three-valued logic.

This type resembles Boolean, but has three values instead of two:

  • Trilean.True (equivalent to true)
  • Trilean.False (equivalent to false)
  • Trilean.Unknown

Trilean supports the same operations that Boolean does, and as long as all values are True or False, the results will be the same. However, the truth tables have to be extended to work with unknown:

not:

-+-
T|F
U|U
F|T

and:

 |T U F
-+-----
T|T U F
U|U U F
F|F F F

or:

 |T U F
-+-----
T|T T T
U|T U U
F|T U F

Trilean is implemented as a value type, so in most cases it will only have the overhead of a single Int. However, in some situations it will be boxed.

Companion
object
object Trilean
Companion
class
class TrileanAlgebra extends DeMorgan[Trilean]
object UByte extends UByteInstances
Companion
class
final
class UByte(val signed: Byte) extends AnyVal with ScalaNumericAnyConversions
Companion
object
object UInt extends UIntInstances
Companion
class
final
class UInt(val signed: Int) extends AnyVal
Companion
object
object ULong extends ULongInstances
Companion
class
final
class ULong(val signed: Long) extends AnyVal
Companion
object
object UShort extends UShortInstances
Companion
class
final
class UShort(val signed: Char) extends AnyVal
Companion
object

Value members

Concrete methods

final
def IEEEremainder(x: Double, d: Double): Double
final
def abs(n: Byte): Byte

abs

abs

final
def abs(n: Short): Short
final
def abs(n: Int): Int
final
def abs(n: Long): Long
final
def abs(n: Float): Float
final
def abs(n: Double): Double
final
def abs[A](a: A)(implicit ev: Signed[A]): A
final
def acos[@specialized(Float, Double) A](a: A)(implicit ev: Trig[A]): A
final
def asin[@specialized(Float, Double) A](a: A)(implicit ev: Trig[A]): A
final
def atan[@specialized(Float, Double) A](a: A)(implicit ev: Trig[A]): A
final
def atan2[@specialized(Float, Double) A](y: A, x: A)(implicit ev: Trig[A]): A
final
def cbrt(x: Double): Double
final
def ceil(n: Float): Float

ceil

ceil

final
def ceil(n: Double): Double
final
def ceil(n: BigDecimal): BigDecimal
final
def ceil[A](a: A)(implicit ev: IsReal[A]): A
def choose(n: Long, k: Long): BigInt

choose (binomial coefficient)

choose (binomial coefficient)

final
def copySign(m: Double, s: Double): Double
final
def copySign(m: Float, s: Float): Float
final
def cos[@specialized(Float, Double) A](a: A)(implicit ev: Trig[A]): A
final
def cosh[@specialized(Float, Double) A](x: A)(implicit ev: Trig[A]): A
final
def cosh(x: Double): Double
final
def e: Double

e

e

final
def e[@specialized(Float, Double) A](implicit ev: Trig[A]): A
def emod(a: Byte, b: Byte): Byte
def emod(a: Short, b: Short): Short
def emod(a: Int, b: Int): Int
def emod(a: Long, b: Long): Long
def emod(a: BigInt, b: BigInt): BigInt
def emod(a: BigInteger, b: BigInteger): BigInteger
def equot(a: Byte, b: Byte): Byte
def equot(a: Short, b: Short): Short
def equot(a: Int, b: Int): Int
def equot(a: Long, b: Long): Long
def equot(a: BigInt, b: BigInt): BigInt
def equot(a: BigInteger, b: BigInteger): BigInteger
def equotmod(a: Byte, b: Byte): (Byte, Byte)

Integer Euclidean division, equotmod, equot, emod

Integer Euclidean division, equotmod, equot, emod

def equotmod(a: Short, b: Short): (Short, Short)
def equotmod(a: Int, b: Int): (Int, Int)
def equotmod(a: Long, b: Long): (Long, Long)
def equotmod(a: BigInt, b: BigInt): (BigInt, BigInt)
def equotmod(a: BigInteger, b: BigInteger): (BigInteger, BigInteger)
final
def exp(n: Double): Double

exp

exp

final
def exp(k: Int, precision: Int): BigDecimal
final
def exp(k: BigDecimal): BigDecimal
final
def exp[A](a: A)(implicit t: Trig[A]): A
final
def expm1(x: Double): Double
def fact(n: Long): BigInt

factorial

factorial

def fib(n: Long): BigInt

fibonacci

fibonacci

final
def floor(n: Float): Float

floor

floor

final
def floor(n: Double): Double
final
def floor(n: BigDecimal): BigDecimal
final
def floor[A](a: A)(implicit ev: IsReal[A]): A
final
def gcd(_x: Long, _y: Long): Long

gcd

gcd

final
def gcd(a: BigInt, b: BigInt): BigInt
final
def gcd[A : Eq](x: A, y: A)(implicit evidence$1: Eq[A], ev: GCDRing[A]): A
final
def gcd[A : Eq](xs: Seq[A])(implicit evidence$2: Eq[A], ev: GCDRing[A]): A
final
def gcd[A : Eq](x: A, y: A, z: A, rest: A*)(implicit evidence$3: Eq[A], ev: GCDRing[A]): A
final
def getExponent(x: Double): Int
final
def getExponent(x: Float): Int
final
def hypot[@specialized(Float, Double) A](x: A, y: A)(implicit f: Field[A], n: NRoot[A], o: Order[A], s: Signed[A]): A
final
def lcm(x: Long, y: Long): Long

lcm

lcm

final
def lcm(a: BigInt, b: BigInt): BigInt
final
def lcm[A : Eq](x: A, y: A)(implicit evidence$4: Eq[A], ev: GCDRing[A]): A
final
def log(n: Double): Double

log

log

final
def log(n: Double, base: Int): Double
final
def log(n: BigDecimal): BigDecimal
def log(n: BigDecimal, base: Int): BigDecimal
final
def log[A](a: A)(implicit t: Trig[A]): A
final
def log[A](a: A, base: Int)(implicit f: Field[A], t: Trig[A]): A
final
def log10(x: Double): Double
final
def log1p(x: Double): Double
final
def max(x: Byte, y: Byte): Byte

max

max

final
def max(x: Short, y: Short): Short
final
def max(x: Int, y: Int): Int
final
def max(x: Long, y: Long): Long
final
def max(x: Float, y: Float): Float
final
def max(x: Double, y: Double): Double
final
def max[A](x: A, y: A)(implicit ev: Order[A]): A
final
def min(x: Byte, y: Byte): Byte

min

min

final
def min(x: Short, y: Short): Short
final
def min(x: Int, y: Int): Int
final
def min(x: Long, y: Long): Long
final
def min(x: Float, y: Float): Float
final
def min(x: Double, y: Double): Double
final
def min[A](x: A, y: A)(implicit ev: Order[A]): A
final
def nextAfter(x: Double, y: Double): Double
final
def nextAfter(x: Float, y: Float): Float
final
def nextUp(x: Double): Double
final
def nextUp(x: Float): Float
def nroot(a: BigDecimal, k: Int, ctxt: MathContext): BigDecimal

An implementation of the shifting n-th root algorithm for BigDecimal. For the BigDecimal a, this is guaranteed to be accurate up to the precision specified in ctxt.

An implementation of the shifting n-th root algorithm for BigDecimal. For the BigDecimal a, this is guaranteed to be accurate up to the precision specified in ctxt.

See http://en.wikipedia.org/wiki/Shifting_nth_root_algorithm

Value Params
a

A (positive if k % 2 == 0) BigDecimal.

ctxt

The MathContext to bound the precision of the result. returns A BigDecimal approximation to the k-th root of a.

k

A positive Int greater than 1.

final
def pi: Double

pi

pi

final
def pi[@specialized(Float, Double) A](implicit ev: Trig[A]): A
final
def pow(base: BigDecimal, exponent: BigDecimal): BigDecimal

pow

pow

final
def pow(base: BigInt, ex: BigInt): BigInt
final
def pow(base: Long, exponent: Long): Long

Exponentiation function, e.g. x^y

Exponentiation function, e.g. x^y

If base^ex doesn't fit in a Long, the result will overflow (unlike Math.pow which will return +/- Infinity).

final
def pow(base: Double, exponent: Double): Double
final
def random: Double
final
def rint(x: Double): Double
final
def round(a: Float): Float

round

round

final
def round(a: Double): Double
final
def round(a: BigDecimal): BigDecimal
final
def round[A](a: A)(implicit ev: IsReal[A]): A
final
def scalb(d: Double, s: Int): Double
final
def scalb(d: Float, s: Int): Float
final
def signum(x: Double): Double

signum

signum

final
def signum(x: Float): Float
final
def signum[A](a: A)(implicit ev: Signed[A]): Int
final
def sin[@specialized(Float, Double) A](a: A)(implicit ev: Trig[A]): A
final
def sinh[@specialized(Float, Double) A](x: A)(implicit ev: Trig[A]): A
final
def sqrt(x: Double): Double

sqrt

sqrt

final
def sqrt[A](a: A)(implicit ev: NRoot[A]): A
final
def tan[@specialized(Float, Double) A](a: A)(implicit ev: Trig[A]): A
final
def tanh[@specialized(Float, Double) A](x: A)(implicit ev: Trig[A]): A
final
def toDegrees(a: Double): Double
final
def toRadians(a: Double): Double
final
def ulp(x: Double): Double
final
def ulp(x: Float): Double