Functional Weave
Code in Python

math.basis-points@2.0.0

impl/python/from_basis_points.py

794 bytes · the Python implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from .math_basis_points_convert_rate import convert_rate  ← convertRate, another function of this group · built into the same file, even by a slim install
from .math_basis_points_types import RateUnit

_MAX_SAFE = 9007199254740991


def from_basis_points(basis_points: int, unit: RateUnit) -> str:
    """Integer basis points as the shortest exact decimal in another unit."""
    if isinstance(basis_points, bool) or not isinstance(basis_points, int):
        raise TypeError("basisPoints must be an integer, received %r" % (basis_points,))
    # Python would go further, but TypeScript cannot, and the three languages
    # must give the same answer or the same error.
    if basis_points > _MAX_SAFE or basis_points < -_MAX_SAFE:
        raise ValueError("basisPoints is outside the safe integer range (±9007199254740991)")
    return convert_rate(str(basis_points), "basis-points", unit)