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

Python Interoperability

From Python

from std.python import Python

var decimal = Python.import_module("decimal")
var py_val = decimal.Decimal("3.14159265358979323846")

var d = Decimal.from_python_decimal(py_val)
# Or:
var d = Decimal(py=py_val)

Matching Python’s API

Many methods mirror Python’s decimal.Decimal API:

Python Decimal methodDecimo equivalent
d.quantize(exp)x.quantize(exp)
d.normalize()x.normalize()
d.as_tuple()x.as_tuple()
d.copy_abs()x.copy_abs()
d.copy_negate()x.copy_negate()
d.copy_sign(other)x.copy_sign(other)
d.fma(a, b)x.fma(a, b)
d.adjusted()x.adjusted()
d.same_quantum(other)x.same_quantum(other)