abstract class NumericModule extends AnyRef
The model of our floating point decimal numbers.
These are numbers of precision 38 (38 decimal digits), and variable scale (from 0 to 37 bounds included).
- Alphabetic
- By Inheritance
- NumericModule
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new NumericModule()
Type Members
- abstract type Numeric <: BigDecimal
Type
Numericrepresents fixed scale BigDecimals, aka Numerics.Type
Numericrepresents fixed scale BigDecimals, aka Numerics. Scale of Numerics can be between0andmaxPrecision(bounds included). For any valid scaleswe denote(Numeric s)the set of Numerics of scales. Numerics are encoded using java BigDecimal, where the scale is the scale of the Numeric.We use java BigDecimals instead of scala ones because:
- We prefer to use here lower level methods from java
- We want two numerics with different scales to be different (w.r.t. ==)
- type Scale = ScaleModule.Scale
- sealed abstract class ScaleModule extends AnyRef
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- val Scale: ScaleModule
- final def add(x: Numeric, y: Numeric): Either[String, Numeric]
Adds the two Numerics.
Adds the two Numerics. The output has the same scale as the inputs. In case of overflow, returns an error message instead.
yandRequires the scale ofxare the same. - final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- final def assertFromBigDecimal(scale: Scale, x: BigDecimal): Numeric
Like
fromBigDecimalbut throws an exception instead of returning e message in case of error.Like
fromBigDecimalbut throws an exception instead of returning e message in case of error.- Annotations
- @throws(scala.this.throws.<init>$default$1[IllegalArgumentException])
- final def assertFromBigDecimal(scale: Scale, x: BigDecimal): Numeric
Like
fromBigDecimalbut throws an exception instead of returning e message in case of error.Like
fromBigDecimalbut throws an exception instead of returning e message in case of error.- Annotations
- @throws(scala.this.throws.<init>$default$1[IllegalArgumentException])
- def assertFromString(s: String): Numeric
Like
fromString, but throws an exception instead of returning a message in case of error.Like
fromString, but throws an exception instead of returning a message in case of error.- Annotations
- @throws(scala.this.throws.<init>$default$1[IllegalArgumentException])
- final def assertFromUnscaledBigDecimal(x: BigDecimal): Numeric
Like fromUnscaledBigDecimal, but throws an exception instead of returning a message in case of error.
Like fromUnscaledBigDecimal, but throws an exception instead of returning a message in case of error.
- Annotations
- @throws(scala.this.throws.<init>$default$1[IllegalArgumentException])
- def checkWithinBoundsAndRound(scale: Scale, x: BigDecimal): Either[String, Numeric]
Like the previous function but with scala BigDecimals instead of java ones.
- def checkWithinBoundsAndRound(scale: Scale, x: BigDecimal): Either[String, Numeric]
Checks that a BigDecimal falls between
minValue(scale)andmaxValue(scale), and round the number according toscale.Checks that a BigDecimal falls between
minValue(scale)andmaxValue(scale), and round the number according toscale. Note that it does _not_ fail if the number contains data beyondscale. - def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- final def compareTo(x: Numeric, y: Numeric): Int
Returns -1, 0, or 1 as
xis numerically less than, equal to, or greater thany.Returns -1, 0, or 1 as
xis numerically less than, equal to, or greater thany.yandRequires the scale ofxare the same. - final def divide(scale: Scale, x: Numeric, y: Numeric): Either[String, Numeric]
Divides
xbyy.Divides
xbyy. The output has the scalescale. If rounding must be performed, the banker's rounding convention is applied. In case of overflow, returns an error message instead. - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def fromBigDecimal(scale: Scale, x: BigDecimal): Either[String, Numeric]
Like
fromBigDecimal(Int, BigDecimal)but with a scala BigDecimal. - final def fromBigDecimal(scale: Scale, x: BigDecimal): Either[String, Numeric]
Converts the java BigDecimal
xto a(Numeric scale). In case scale is not a valid Numeric scale orxcannot be represented as a(Numeric scale)without loss of precision, returns an error message instead. - final def fromLong(scale: Scale, x: Long): Either[String, Numeric]
Converts the Long
xto a(Numeric scale). In case scale is not a valid Numeric scale orxcannot be represented as a(Numeric scale), returns an error message instead. - def fromString(s: String): Either[String, Numeric]
Given a string representation of a decimal returns the corresponding Numeric, where the number of digits to the right of the decimal point indicates the scale.
Given a string representation of a decimal returns the corresponding Numeric, where the number of digits to the right of the decimal point indicates the scale. If the input does not match
-?([1-9]\d*|0).(\d*)or if the result of the conversion cannot be mapped into a numeric without loss of precision returns an error message instead. - final def fromUnscaledBigDecimal(x: BigDecimal): Either[String, Numeric]
Like the previous function but with scala BigDecimal
- final def fromUnscaledBigDecimal(x: BigDecimal): Either[String, Numeric]
Convert a BigDecimal to the Numeric with the smallest possible scale able to represent the former without loss of precision.
Convert a BigDecimal to the Numeric with the smallest possible scale able to represent the former without loss of precision. Returns an error if such Numeric does not exists.
Use this function to convert BigDecimal with unknown scale.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- val maxPrecision: Int
Maximum usable precision for Numerics
- final def maxValue(scale: Scale): Numeric
Returns the largest Numeric of scale
scale - final def minValue(scale: Scale): Numeric
Returns the smallest Numeric of scale
scale - final def multiply(scale: Scale, x: Numeric, y: Numeric): Either[String, Numeric]
Multiplies
xbyy.Multiplies
xbyy. The output has the scalescale. If rounding must be performed, the banker's rounding convention is applied. In case of overflow, returns an error message instead. - final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def negate(x: Numeric): Numeric
Negate the input.
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def round(targetScale: Long, x: Numeric): Either[String, Numeric]
Rounds the
xto the closest multiple of10^targetScaleusing the banker's rounding convention. The output has the same scale as the input. In case of overflow, returns an error message instead. - final def scale(numeric: Numeric): Scale
- final def subtract(x: Numeric, y: Numeric): Either[String, Numeric]
Subtracts
ytox.Subtracts
ytox. The output has the same scale as the inputs. In case of overflow, returns an error message instead.yandRequires the scale ofxare the same. - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- final def toLong(x: Numeric): Either[String, Long]
Returns the integral part of the given decimal, in other words, rounds towards 0.
Returns the integral part of the given decimal, in other words, rounds towards 0. In case the result does not fit into a long, returns an error message instead.
yandRequires the scale ofxare the same. - final def toString(x: BigDecimal): String
Returns a canonical decimal string representation of
x.Returns a canonical decimal string representation of
x. The output string consists of (in left-to-right order): - An optional negative sign ("-") to indicate ifxis strictly negative. - The integral part ofxwithout leading '0' if the integral part ofxis not equal to 0, "0" otherwise. - the decimal point (".") to separate the integral part from the decimal part, - the decimal part ofxwith '0' padded to match the scale. The number of decimal digits must be the same as the scale. - def toString(): String
- Definition Classes
- AnyRef → Any
- final def toUnscaledString(x: BigDecimal): String
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated