math.big #

Constants #

const (
	zero_int = Integer{
		digits: []u32{len: 0}
		signum: 0
	}
	one_int = Integer{
		digits: [u32(1)]
		signum: 1
	}
	two_int = Integer{
		digits: [u32(2)]
		signum: 1
	}
)

fn integer_from_bytes #

fn integer_from_bytes(input []byte, config IntegerConfig) Integer

fn integer_from_i64 #

fn integer_from_i64(value i64) Integer

fn integer_from_int #

fn integer_from_int(value int) Integer

fn integer_from_radix #

fn integer_from_radix(all_characters string, radix u32) ?Integer

fn integer_from_string #

fn integer_from_string(characters string) ?Integer

fn integer_from_u32 #

fn integer_from_u32(value u32) Integer

fn integer_from_u64 #

fn integer_from_u64(value u64) Integer

struct Integer #

struct Integer {
	digits []u32
pub:
	signum int
}

big.Integer

It has the following properties:

  1. Every "digit" is an integer in the range [0, 2^32).
  2. The signum can be one of three values: -1, 0, +1 for negative, zero, and positive values, respectively.
  3. There should be no leading zeros in the digit array.
  4. The digits are stored in little endian format, that is, the digits with a lower positional value (towards the right when represented as a string) have a lower index, and vice versa.

fn (Integer) abs #

fn (integer Integer) abs() Integer

fn (Integer) neg #

fn (integer Integer) neg() Integer

fn (Integer) + #

fn (integer Integer) + (addend Integer) Integer

fn (Integer) - #

fn (integer Integer) - (subtrahend Integer) Integer

fn (Integer) * #

fn (integer Integer) * (multiplicand Integer) Integer

fn (Integer) div_mod #

fn (integer Integer) div_mod(divisor Integer) (Integer, Integer)

fn (Integer) / #

fn (a Integer) / (b Integer) Integer

fn (Integer) % #

fn (a Integer) % (b Integer) Integer

fn (Integer) pow #

fn (a Integer) pow(exponent u32) Integer

fn (Integer) mod_pow #

fn (a Integer) mod_pow(exponent u32, divisor Integer) Integer

fn (Integer) inc #

fn (mut a Integer) inc()

fn (Integer) dec #

fn (mut a Integer) dec()

fn (Integer) == #

fn (a Integer) == (b Integer) bool

fn (Integer) abs_cmp #

fn (a Integer) abs_cmp(b Integer) int

fn (Integer) < #

fn (a Integer) < (b Integer) bool

fn (Integer) bitwise_or #

fn (a Integer) bitwise_or(b Integer) Integer

fn (Integer) bitwise_and #

fn (a Integer) bitwise_and(b Integer) Integer

fn (Integer) bitwise_not #

fn (a Integer) bitwise_not() Integer

fn (Integer) bitwise_xor #

fn (a Integer) bitwise_xor(b Integer) Integer

fn (Integer) lshift #

fn (a Integer) lshift(amount u32) Integer

fn (Integer) rshift #

fn (a Integer) rshift(amount u32) Integer

fn (Integer) binary_str #

fn (integer Integer) binary_str() string

fn (Integer) hex #

fn (integer Integer) hex() string

fn (Integer) radix_str #

fn (integer Integer) radix_str(radix u32) string

fn (Integer) str #

fn (integer Integer) str() string

fn (Integer) int #

fn (a Integer) int() int

fn (Integer) bytes #

fn (a Integer) bytes() ([]byte, int)

fn (Integer) gcd #

fn (a Integer) gcd(b Integer) Integer

fn (Integer) factorial #

fn (a Integer) factorial() Integer

fn (Integer) isqrt #

fn (a Integer) isqrt() Integer

isqrt returns the closest integer square root of the given integer.

fn (Integer) gcd_binary #

fn (x Integer) gcd_binary(y Integer) Integer

Greatest-Common-Divisor https://en.wikipedia.org/wiki/Binary_GCD_algorithm The code below follows the 2013-christmas-special by D. Lemire & R. Corderoy https://en.algorithmica.org/hpc/analyzing-performance/gcd/

discussion & further info https://lemire.me/blog/2013/12/26/fastest-way-to-compute-the-greatest-common-divisor/

struct IntegerConfig #

struct IntegerConfig {
	signum int = 1
}