class BigDecimal
source · line 7public class BigDecimal internal constructor(
private val coefficient: IntegerStorage,
/** The decimal scale; negative scales represent integer powers of ten. */
public val scale: Long
) : Equals<BigDecimal>, Compare<BigDecimal>, Hash, ToString, Add<BigDecimal, BigDecimal>, Sub<BigDecimal, BigDecimal>, Mul<BigDecimal, BigDecimal>, Div<BigDecimal, BigDecimal>, Rem<BigDecimal, BigDecimal>, UnaryPlus<BigDecimal>, UnaryMinus<BigDecimal>, Increment<BigDecimal>, Decrement<BigDecimal>
- Supertype
Equals<BigDecimal> - Supertype
Compare<BigDecimal> - Supertype
Hash - Supertype
ToString - Supertype
Add<BigDecimal, BigDecimal> - Supertype
Sub<BigDecimal, BigDecimal> - Supertype
Mul<BigDecimal, BigDecimal> - Supertype
Div<BigDecimal, BigDecimal> - Supertype
Rem<BigDecimal, BigDecimal> - Supertype
UnaryPlus<BigDecimal> - Supertype
UnaryMinus<BigDecimal> - Supertype
Increment<BigDecimal> - Supertype
Decrement<BigDecimal>
An immutable arbitrary-precision decimal, coefficient * 10^(-scale). Equality and hashing compare numerical values, ignoring scale; sameRepresentation compares stored representations.
function toFloat
source · line 153public fun toFloat(): Float
Rounds directly to binary32, allowing infinity and signed underflow zero.
property signum
source · line 26public val signum: Int
get: public read-only
The mathematical sign: -1, 0, or 1.
getter get
source · line 26get(): Int
function unscaledValue
source · line 28public fun unscaledValue(): BigInteger
Returns the immutable signed coefficient, without applying the scale.
function toShortExact
source · line 163public fun toShortExact(): Short
Requires both an integral value and a representable Short; otherwise throws ArithmeticException.
function unaryPlus
source · line 59public override operator fun unaryPlus(): BigDecimal
- Overrides
unaryPlus
Retains this immutable representation.
function pow
source · line 120public fun pow(exponent: Long): BigDecimal
Returns an exact nonnegative integer power; 0^0 is one and negative exponents throw.
parameter exponent
source · line 120exponent: Long
function setScale
source · line 133public fun setScale(scale: Long, roundingMode: RoundingMode = RoundingMode.Unnecessary): BigDecimal
Rescales exactly or rounds explicitly; the default rejects a nonzero discarded fraction.
parameter scale
source · line 133scale: Long
parameter roundingMode
source · line 133roundingMode: RoundingMode = RoundingMode.Unnecessary
function toEngineeringString
source · line 46public fun toEngineeringString(): String
Uses an exponent divisible by three when scientific notation is needed.
function movePointLeft
source · line 137public fun movePointLeft(distance: Long): BigDecimal
Moves the point left and clamps the resulting scale to at least zero.
parameter distance
source · line 137distance: Long
function toByteExact
source · line 159public fun toByteExact(): Byte
Requires both an integral value and a representable Byte; otherwise throws ArithmeticException.
function pow
source · line 122public fun pow(exponent: Long, context: MathContext): BigDecimal
Rounds the exact power once; finite precision also permits negative exponents.
parameter context
source · line 122context: MathContext
parameter exponent
source · line 122exponent: Long
function toBigInteger
source · line 149public fun toBigInteger(): BigInteger
Truncates toward zero and returns an immutable integer.
function equals
source · line 34public override operator fun equals(other: BigDecimal): Boolean
- Overrides
equals
Compares mathematical values; scale and redundant trailing zeros do not affect equality.
parameter other
source · line 34other: BigDecimal
function rem
source · line 113public fun rem(other: BigDecimal, context: MathContext): BigDecimal
Returns the exact remainder; the context limits only the integral quotient.
parameter other
source · line 113other: BigDecimal
parameter context
source · line 113context: MathContext
function toULongExact
source · line 187public fun toULongExact(): ULong
Requires both an integral value and a representable ULong; otherwise throws ArithmeticException.
function divideAndRemainder
source · line 106public fun divideAndRemainder(other: BigDecimal, context: MathContext = MathContext.Unlimited): (BigDecimal, BigDecimal)
Returns the integral quotient and exact remainder; the context limits only the quotient.
parameter other
source · line 106other: BigDecimal
parameter context
source · line 106context: MathContext = MathContext.Unlimited
function max
source · line 71public fun max(other: BigDecimal): BigDecimal
Returns the larger value, retaining this instance on numeric equality.
parameter other
source · line 71other: BigDecimal
function inc
source · line 63public override operator fun inc(): BigDecimal
- Overrides
inc
Returns this value plus the scale-zero constant one.
function toIntExact
source · line 167public fun toIntExact(): Int
Requires both an integral value and a representable Int; otherwise throws ArithmeticException.
function scaleByPowerOfTen
source · line 135public fun scaleByPowerOfTen(exponent: Long): BigDecimal
Multiplies exactly by a power of ten without changing the coefficient.
parameter exponent
source · line 135exponent: Long
function sameRepresentation
source · line 40public fun sameRepresentation(other: BigDecimal): Boolean
Compares both the coefficient and scale.
parameter other
source · line 40other: BigDecimal
function toUByteExact
source · line 175public fun toUByteExact(): UByte
Requires both an integral value and a representable UByte; otherwise throws ArithmeticException.
function compareTo
source · line 36public override operator fun compareTo(other: BigDecimal): Long
- Overrides
compareTo
Orders mathematical values, returning -1, 0, or 1 without expanding large scale gaps.
parameter other
source · line 36other: BigDecimal
function toUShortExact
source · line 179public fun toUShortExact(): UShort
Requires both an integral value and a representable UShort; otherwise throws ArithmeticException.
function div
source · line 55public override operator fun div(other: BigDecimal): BigDecimal
- Overrides
div
Returns the exact finite decimal quotient; zero division or a nonterminating result throws.
parameter other
source · line 55other: BigDecimal
function stripTrailingZeros
source · line 147public fun stripTrailingZeros(): BigDecimal
Removes decimal coefficient zeros; zero becomes ZERO, and an unrepresentable nonzero scale throws.
function toShort
source · line 161public fun toShort(): Short
Truncates toward zero and retains the target integer's low bits.
function toUInt
source · line 181public fun toUInt(): UInt
Truncates toward zero and retains the target integer's low bits.
function toUShort
source · line 177public fun toUShort(): UShort
Truncates toward zero and retains the target integer's low bits.
function plus
source · line 74public fun plus(other: BigDecimal, context: MathContext): BigDecimal
Rounds the mathematical sum once to the explicit significant-digit context.
parameter context
source · line 74context: MathContext
parameter other
source · line 74other: BigDecimal
constructor constructor
source · line 16constructor(value: Long)
Constructs an exact signed integer with scale zero.
parameter value
source · line 16value: Long
function movePointRight
source · line 142public fun movePointRight(distance: Long): BigDecimal
Moves the point right and clamps the resulting scale to at least zero.
parameter distance
source · line 142distance: Long
function round
source · line 96public fun round(context: MathContext): BigDecimal
Rounds once to the requested significant digits; negative precision is invalid.
parameter context
source · line 96context: MathContext
function toDouble
source · line 155public fun toDouble(): Double
Rounds directly to binary64, allowing infinity and signed underflow zero.
property scale
source · line 10public val scale: Long
get: public read-only
The decimal scale; negative scales represent integer powers of ten.
function sqrt
source · line 127public fun sqrt(context: MathContext = MathContext.Unlimited): BigDecimal
Rounds the mathematical square root once; unlimited precision requires a finite exact root.
parameter context
source · line 127context: MathContext = MathContext.Unlimited
function toUIntExact
source · line 183public fun toUIntExact(): UInt
Requires both an integral value and a representable UInt; otherwise throws ArithmeticException.
function toLongExact
source · line 171public fun toLongExact(): Long
Requires both an integral value and a representable Long; otherwise throws ArithmeticException.
function div
source · line 94public fun div(other: BigDecimal, scale: Long, roundingMode: RoundingMode): BigDecimal
Divides at the requested fixed scale, using the explicit rounding mode.
parameter scale
source · line 94scale: Long
parameter other
source · line 94other: BigDecimal
parameter roundingMode
source · line 94roundingMode: RoundingMode
function plus
source · line 49public override operator fun plus(other: BigDecimal): BigDecimal
- Overrides
plus
Returns the exact sum at the larger operand scale.
parameter other
source · line 49other: BigDecimal
function toBigIntegerExact
source · line 151public fun toBigIntegerExact(): BigInteger
Converts only if there is no fractional part; otherwise throws ArithmeticException.
function toString
source · line 42public override fun toString(): String
- Overrides
toString
Returns the canonical decimal text, preserving the coefficient and scale on parsing.
function rem
source · line 57public override operator fun rem(other: BigDecimal): BigDecimal
- Overrides
rem
Returns the exact remainder after division toward zero; a zero divisor throws.
parameter other
source · line 57other: BigDecimal
function toUByte
source · line 173public fun toUByte(): UByte
Truncates toward zero and retains the target integer's low bits.
function toByte
source · line 157public fun toByte(): Byte
Truncates toward zero and retains the target integer's low bits.
function unaryMinus
source · line 61public override operator fun unaryMinus(): BigDecimal
- Overrides
unaryMinus
Negates the coefficient, preserving scale.
constructor constructor
source · line 20constructor(unscaledValue: BigInteger, scale: Long = 0L)
Shares the immutable integer coefficient at the requested scale.
parameter scale
source · line 20scale: Long = 0L
parameter unscaledValue
source · line 20unscaledValue: BigInteger
function divideToIntegralValue
source · line 101public fun divideToIntegralValue(other: BigDecimal, context: MathContext = MathContext.Unlimited): BigDecimal
Returns the integral quotient toward zero; finite precision must represent it exactly.
parameter other
source · line 101other: BigDecimal
parameter context
source · line 101context: MathContext = MathContext.Unlimited
function times
source · line 84public fun times(other: BigDecimal, context: MathContext): BigDecimal
Rounds the mathematical product once to the explicit context.
parameter other
source · line 84other: BigDecimal
parameter context
source · line 84context: MathContext
function toPlainString
source · line 44public fun toPlainString(): String
Formats without an exponent; parsing preserves the numeric value.
function abs
source · line 67public fun abs(): BigDecimal
Returns the absolute value, preserving scale.
function toULong
source · line 185public fun toULong(): ULong
Truncates toward zero and retains the target integer's low bits.
function ulp
source · line 32public fun ulp(): BigDecimal
Returns one unit in the last stored place, at this scale.
function times
source · line 53public override operator fun times(other: BigDecimal): BigDecimal
- Overrides
times
Returns the exact product at the sum of operand scales.
parameter other
source · line 53other: BigDecimal
function div
source · line 89public fun div(other: BigDecimal, context: MathContext): BigDecimal
Divides using explicit significant digits; unlimited precision requires a finite exact result.
parameter context
source · line 89context: MathContext
parameter other
source · line 89other: BigDecimal
function toInt
source · line 165public fun toInt(): Int
Truncates toward zero and retains the target integer's low bits.
function min
source · line 69public fun min(other: BigDecimal): BigDecimal
Returns the smaller value, retaining this instance on numeric equality.
parameter other
source · line 69other: BigDecimal
function hash
source · line 38public override fun hash(): Long
- Overrides
hash
Hashes the mathematical value, consistently across all equivalent representations.
constructor constructor
source · line 18constructor(value: ULong)
Constructs an exact unsigned integer with scale zero.
parameter value
source · line 18value: ULong
function toLong
source · line 169public fun toLong(): Long
Truncates toward zero and retains the target integer's low bits.
constructor constructor
source · line 22constructor(unscaledValue: Long, scale: Long)
Constructs a signed coefficient at the requested scale.
parameter unscaledValue
source · line 22unscaledValue: Long
parameter scale
source · line 22scale: Long
function precision
source · line 30public fun precision(): Long
Returns the coefficient's decimal digit count, with precision one for zero.
function dec
source · line 65public override operator fun dec(): BigDecimal
- Overrides
dec
Returns this value minus the scale-zero constant one.
function minus
source · line 79public fun minus(other: BigDecimal, context: MathContext): BigDecimal
Rounds the mathematical difference once to the explicit context.
parameter context
source · line 79context: MathContext
parameter other
source · line 79other: BigDecimal
function minus
source · line 51public override operator fun minus(other: BigDecimal): BigDecimal
- Overrides
minus
Returns the exact difference at the larger operand scale.
parameter other
source · line 51other: BigDecimal