Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Query Methods (Decimal)

MethodReturnDescription
x.is_zero()BoolTrue if value is zero
x.is_one()BoolTrue if value is exactly 1
x.is_integer()BoolTrue if no fractional part
x.is_negative()BoolTrue if negative
x.is_positive()BoolTrue if strictly positive
x.is_odd()BoolTrue if odd integer
x.number_of_digits()IntTotal digits in coefficient
x.adjusted()IntAdjusted exponent (≈ floor(log10(|x|)))
x.same_quantum(y)BoolTrue if both have same scale

as_tuple() — Python-compatible decomposition

var parts = Decimal("7.25").as_tuple()
# parts[0] = False (sign), parts[1] = [7, 2, 5] (digits), parts[2] = -2 (exponent)
# sign=False, digits=[7, 2, 5], exp=-2

Other methods

x.copy_abs()             # Copy with positive sign
x.copy_negate()          # Copy with inverted sign
x.copy_sign(other)       # Copy of x with sign of other
x.fma(a, b)              # Fused multiply-add: x*a+b (exact)
x.scaleb(n)              # Multiply by 10^n (O(1), adjusts scale only)