std/math/bignum

Standard Library documentation

Arbitrary precision BigNum class.

Module

Name
std/math/bignum
Area
Standard Library
Source
modules/std/math/bignum.zzm

NAME

std/math/bignum - Arbitrary precision BigNum class.

SYNOPSIS

  from std/math/bignum import BigNum;

  let n := BigNum.from_dec("12345");
  let m := BigNum.from_hex("0xABCDEF");
  let p := BigNum.from_dec("-12345.6789");

  say m.badd(n).to_dec;
  say p.babs.to_dec;

IMPLEMENTATION SUPPORT

This module is supported by all implementations of ZuzuScript.

DESCRIPTION

This module exports BigNum, a class for working with integers and floating-point numbers at arbitrary precision.

EXPORTS

Classes

  • BigNum

    Runtime-supported arbitrary precision number class.

    • BigNum.from_dec(String text)

      Parameters: text is a decimal number string. Returns: BigNum. Constructs a big number from decimal text.

    • BigNum.from_hex(String text)

      Parameters: text is a hexadecimal integer string. Returns: BigNum. Constructs a big number from hexadecimal text.

    • value.is_int()

      Parameters: none. Returns: Boolean. Returns true when the value is an integer.

    • value.bcmp(other), value.beq(other), value.bne(other), value.blt(other), value.ble(other), value.bgt(other), value.bge(other)

      Parameters: other is a number-like value. Returns: Number for bcmp and Boolean for the predicate methods. Compares two big numbers.

    • value.babs(), value.bneg(), value.binv()

      Parameters: none. Returns: BigNum. Returns the absolute value, negation, or reciprocal.

    • value.bsin(), value.bcos(), value.btan(), value.bsqrt()

      Parameters: none. Returns: BigNum. Returns the trigonometric or square-root result.

    • value.bround(), value.bfloor(), value.bceil()

      Parameters: none. Returns: BigNum. Rounds the big number.

    • value.badd(other), value.bsub(other), value.bmul(other), value.bdiv(other), value.bmod(other), value.bpow(other)

      Parameters: other is a number-like value. Returns: BigNum. Performs arithmetic with another value.

    • value.to_hex(), value.to_dec(), value.to_String()

      Parameters: none. Returns: String. Converts the big number to text.

    • value.to_Number()

      Parameters: none. Returns: Number. Converts the big number to a native number.

COPYRIGHT AND LICENCE

std/math/bignum is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.