Multi precision Integer numbers.

Introduced properties

fun %(i: BigInt): BigInt

gmp :: BigInt :: %

Modulo of `self` with `i`.
fun **(e: Int): BigInt

gmp :: BigInt :: **

Returns `self` raised to the power of `e`.
fun abs: BigInt

gmp :: BigInt :: abs

The absolute value of `self`.
init defaultinit(val: NativeMPZ)

gmp :: BigInt :: defaultinit

fun gcd(i: BigInt): BigInt

gmp :: BigInt :: gcd

Returns the greatest common divisor of `self` and `i`
fun next_prime: BigInt

gmp :: BigInt :: next_prime

Return the next prime number greater than `self`.
fun probab_prime(reps: Int): Int

gmp :: BigInt :: probab_prime

Determine if `self` is a prime number.

Redefined properties

redef fun *(i: OTHER): OTHER

gmp \$ BigInt :: *

`assert(2.to_bi * 2.to_bi == 4.to_bi)`
redef fun +(i: OTHER): OTHER

gmp \$ BigInt :: +

`assert(2.to_bi + 2.to_bi == 4.to_bi)`
redef fun -(i: OTHER): OTHER

gmp \$ BigInt :: -

`assert(2.to_bi - 2.to_bi == 0.to_bi)`
redef fun /(i: OTHER): OTHER

gmp \$ BigInt :: /

`assert(3.to_bi / 2.to_bi == 1.to_bi)`
redef fun <(i: OTHER): Bool

gmp \$ BigInt :: <

Is `self` lesser than `other`?
redef fun <=(i: OTHER): Bool

gmp \$ BigInt :: <=

not `other` < `self`
redef fun <=>(i: OTHER): Int

gmp \$ BigInt :: <=>

-1 if <, +1 if > and 0 otherwise
redef fun ==(i: nullable Object): Bool

gmp \$ BigInt :: ==

Have `self` and `other` the same value?
redef fun >(i: OTHER): Bool

gmp \$ BigInt :: >

`other` < `self`
redef fun >=(i: OTHER): Bool

gmp \$ BigInt :: >=

not `self` < `other`
redef type OTHER: BigInt

gmp \$ BigInt :: OTHER

What `self` can be compared to?
redef type SELF: BigInt

gmp \$ BigInt :: SELF

Type of this instance, automatically specialized in every class
redef fun distance(i: OTHER): Int

gmp \$ BigInt :: distance

`assert(3.to_bi.distance(6.to_bi) == -3)`
redef fun finalize_once

gmp \$ BigInt :: finalize_once

Real finalization method of `FinalizableOnce`, will be called only once
redef fun hash: Int

gmp \$ BigInt :: hash

The hash code of the object.
redef fun predecessor(i: Int): OTHER

gmp \$ BigInt :: predecessor

The previous element.
redef fun successor(i: Int): OTHER

gmp \$ BigInt :: successor

The next element.
redef fun to_bi: BigInt

gmp \$ BigInt :: to_bi

The BigInt equivalent of `self`
redef fun to_f: Float

gmp \$ BigInt :: to_f

`assert(11.to_bi.to_f == 11.0)`
redef fun to_i: Int

gmp \$ BigInt :: to_i

`assert(11.to_bi.to_i == 11)`
redef fun to_r: Ratio

gmp \$ BigInt :: to_r

`assert(123.to_bi.to_r == 123.to_r)`
redef fun to_s: String

gmp \$ BigInt :: to_s

`assert(11.to_bi.to_s == "11")`
redef fun unary -: OTHER

gmp \$ BigInt :: unary -

`assert(-(2.to_bi) == (-2).to_bi)`
redef fun value_of(i: Numeric): OTHER

gmp \$ BigInt :: value_of

`assert(11.to_bi.value_of(4) == 4.to_bi)`
redef fun zero: OTHER

gmp \$ BigInt :: zero

`assert(11.to_bi.zero == 0.to_bi)`

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have `self` and `other` different values?
fun %(i: BigInt): BigInt

gmp :: BigInt :: %

Modulo of `self` with `i`.
abstract fun *(i: OTHER): OTHER

core :: Numeric :: *

Multiplication of `self` with `i`
fun **(e: Int): BigInt

gmp :: BigInt :: **

Returns `self` raised to the power of `e`.
abstract fun +(i: OTHER): OTHER

core :: Numeric :: +

Addition of `self` with `i`
abstract fun -(i: OTHER): OTHER

core :: Numeric :: -

Substraction of `i` from `self`
abstract fun /(i: OTHER): OTHER

core :: Numeric :: /

Division of `self` with `i`
abstract fun <(other: OTHER): Bool

core :: Comparable :: <

Is `self` lesser than `other`?
fun <=(other: OTHER): Bool

core :: Comparable :: <=

not `other` < `self`
fun <=>(other: OTHER): Int

core :: Comparable :: <=>

-1 if <, +1 if > and 0 otherwise
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have `self` and `other` the same value?
fun >(other: OTHER): Bool

core :: Comparable :: >

`other` < `self`
fun >=(other: OTHER): Bool

core :: Comparable :: >=

not `self` < `other`
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type OTHER: Comparable

core :: Comparable :: OTHER

What `self` can be compared to?
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun abs: BigInt

gmp :: BigInt :: abs

The absolute value of `self`.

Universal `+` with any `Numeric`
fun clamp(min: OTHER, max: OTHER): OTHER

core :: Comparable :: clamp

Constraint `self` within `[min..max]`
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by `get_class` to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
init defaultinit(val: NativeMPZ)

gmp :: BigInt :: defaultinit

init defaultinit

core :: FinalizableOnce :: defaultinit

init defaultinit

core :: Finalizable :: defaultinit

init defaultinit

core :: Comparable :: defaultinit

init defaultinit

core :: Numeric :: defaultinit

init defaultinit

core :: Object :: defaultinit

init defaultinit

core :: Discrete :: defaultinit

fun distance(d: OTHER): Int

core :: Discrete :: distance

The distance between self and d.
abstract fun div(other: Numeric): Numeric

core :: Numeric :: div

Universal `/` with any `Numeric`
fun finalize

core :: Finalizable :: finalize

Liberate any resources held by `self` before the memory holding `self` is freed
protected fun finalize_once

core :: FinalizableOnce :: finalize_once

Real finalization method of `FinalizableOnce`, will be called only once
fun finalized: Bool

core :: FinalizableOnce :: finalized

Has `self` been finalized? (either by the GC or an explicit call to `finalize`)
protected fun finalized=(finalized: Bool)

core :: FinalizableOnce :: finalized=

Has `self` been finalized? (either by the GC or an explicit call to `finalize`)
fun gcd(i: BigInt): BigInt

gmp :: BigInt :: gcd

Returns the greatest common divisor of `self` and `i`
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of `self`.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of `self`.

Return "CLASSNAME:#OBJECTID".
fun is_between(c: OTHER, d: OTHER): Bool

core :: Comparable :: is_between

c <= self <= d
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if `self` and `other` are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is `self` the same as `other` in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if `self` and `other` have the same dynamic type.
fun is_zero: Bool

core :: Numeric :: is_zero

Is this the value of zero in its domain?
fun max(other: OTHER): OTHER

core :: Comparable :: max

The maximum between `self` and `other` (prefers `self` if equals).
fun min(c: OTHER): OTHER

core :: Comparable :: min

The minimum between `self` and `c` (prefer `self` if equals)
abstract fun mul(other: Numeric): Numeric

core :: Numeric :: mul

Universal `*` with any `Numeric`
fun next_prime: BigInt

gmp :: BigInt :: next_prime

Return the next prime number greater than `self`.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
abstract fun predecessor(i: Int): OTHER

core :: Discrete :: predecessor

The previous element.
fun probab_prime(reps: Int): Int

gmp :: BigInt :: probab_prime

Determine if `self` is a prime number.
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
abstract fun sub(other: Numeric): Numeric

core :: Numeric :: sub

Universal `-` with any `Numeric`
abstract fun successor(i: Int): OTHER

core :: Discrete :: successor

The next element.
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the `Sys` class.
abstract fun to_b: Byte

core :: Numeric :: to_b

The byte equivalent of `self`
fun to_bi: BigInt

core :: Numeric :: to_bi

The BigInt equivalent of `self`
abstract fun to_f: Float

core :: Numeric :: to_f

The float equivalent of `self`
abstract fun to_i: Int

core :: Numeric :: to_i

The integer part of `self`.
fun to_i16: Int16

core :: Numeric :: to_i16

The Int16 equivalent of `self`
fun to_i32: Int32

core :: Numeric :: to_i32

The Int32 equivalent of `self`
fun to_i8: Int8

core :: Numeric :: to_i8

The Int8 equivalent of `self`
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_r: Ratio

core :: Numeric :: to_r

The Ratio equivalent of `self`
fun to_s: String

core :: Object :: to_s

User readable representation of `self`.
fun to_u16: UInt16

core :: Numeric :: to_u16

The UInt16 equivalent of `self`
fun to_u32: UInt32

core :: Numeric :: to_u32

The UInt32 equivalent of `self`
abstract fun unary -: OTHER

core :: Numeric :: unary -

Inverse of `self`
abstract fun value_of(val: Numeric): OTHER

core :: Numeric :: value_of

The value of `val` in the domain of `self`
abstract fun zero: OTHER

core :: Numeric :: zero

The value of zero in the domain of `self`

Ancestors

interface Comparable

core :: Comparable

The ancestor of class where objects are in a total order.
class Finalizable

core :: Finalizable

An object needing finalization
interface Object

core :: Object

The root of the class hierarchy.

Parents

interface Discrete

core :: Discrete

Discrete total orders.
class FinalizableOnce

core :: FinalizableOnce

An object to be finalized only once
interface Numeric

core :: Numeric

A numeric value supporting mathematical operations

Class definitions

gmp \$ BigInt
```# Multi precision Integer numbers.
class BigInt
super Discrete
super Numeric
super FinalizableOnce

redef type OTHER: BigInt

private var val: NativeMPZ

redef fun successor(i) do return self + i.to_bi
redef fun predecessor(i) do return self - i.to_bi

redef fun hash do return self.to_i

redef fun <=>(i) do
var res = val.cmp(i.val)
if (res) < 0 then
return -1
else if (res) > 0 then
return 1
else
return 0
end
end

redef fun ==(i) do return i isa BigInt and (self <=> i) == 0
redef fun <=(i) do return (self <=> i) <= 0
redef fun <(i) do return (self <=> i) < 0
redef fun >=(i) do return (self <=> i) >= 0
redef fun >(i) do return (self <=> i) > 0

#     assert(2.to_bi + 2.to_bi == 4.to_bi)
redef fun +(i) do
var res = new NativeMPZ
return new BigInt(res)
end

#     assert(-(2.to_bi) == (-2).to_bi)
redef fun - do
var res = new NativeMPZ
val.neg res
return new BigInt(res)
end

#     assert(2.to_bi - 2.to_bi == 0.to_bi)
redef fun -(i) do
var res = new NativeMPZ
val.sub(res, i.val)
return new BigInt(res)
end

#     assert(2.to_bi * 2.to_bi == 4.to_bi)
redef fun *(i) do
var res = new NativeMPZ
val.mul(res, i.val)
return new BigInt(res)
end

#     assert(3.to_bi / 2.to_bi == 1.to_bi)
redef fun /(i) do
var res = new NativeMPZ
val.tdiv_q(res, i.val)
return new BigInt(res)
end

# Modulo of `self` with `i`.
#
# Finds the remainder of the division of `self` by `i`.
#
#     assert(5.to_bi % 2.to_bi == 1.to_bi)
fun %(i: BigInt): BigInt do
var res = new NativeMPZ
val.mod(res, i.val)
return new BigInt(res)
end

# Returns `self` raised to the power of `e`.
#
#     assert(3.to_bi ** 2 == 9.to_bi)
fun **(e: Int): BigInt do
var res = new NativeMPZ
var pow = new UInt64
pow.set_si e
val.pow_ui(res, pow)
pow.free
return new BigInt(res)
end

# The absolute value of `self`.
#
#     assert((-3).to_bi.abs == 3.to_bi)
fun abs: BigInt do
var res = new NativeMPZ
val.abs res
return new BigInt(res)
end

# Returns the greatest common divisor of `self` and `i`
#
#     assert(15.to_bi.gcd(10.to_bi) == 5.to_bi)
fun gcd(i: BigInt): BigInt do
var res = new NativeMPZ
val.gcd(res, i.val)
return new BigInt(res)
end

# Determine if `self` is a prime number.
# Return 2 if `self` is prime, return 1 if `self` is probably prime and
# return 0 if `self` is definitely not a prime number.
#
# This function begins by trying some divisions with small number to find if
# there is other factors then `self` and one. After that, it uses the
# Miller-Rabin probabilistic primality tests. The probability of a non-prime
# being identified as probably prime with that test is less than
# `4^(-reps)`. It is recommended to use a `reps` value between 15 and 50.
#
#     assert((0x10001).to_bi.probab_prime(15) == 2)
fun probab_prime(reps: Int): Int do
return val.probab_prime_p(reps.to_i32)
end

# Return the next prime number greater than `self`.
# This fonction uses a probabilistic algorithm.
#
#     assert(11.to_bi.next_prime == 13.to_bi)
fun next_prime: BigInt do
var res = new NativeMPZ
val.nextprime res
return new BigInt(res)
end

#     assert(11.to_bi.zero == 0.to_bi)
redef fun zero do return new BigInt(new NativeMPZ)

#     assert(11.to_bi.value_of(4) == 4.to_bi)
redef fun value_of(i) do return i.to_bi

#     assert(11.to_bi.to_i == 11)
redef fun to_i do return val.get_si

#     assert(11.to_bi.to_f == 11.0)
redef fun to_f do return val.get_d

#     assert(11.to_bi.to_s == "11")
redef fun to_s do
var cstr = val.get_str(10.to_i32)
var str = cstr.to_s
cstr.free
return str
end

redef fun to_bi do return self

#     assert(123.to_bi.to_r == 123.to_r)
redef fun to_r do
var tmp = new NativeMPQ
tmp.set_z val
return new Ratio(tmp)
end

#     assert(3.to_bi.distance(6.to_bi) == -3)
redef fun distance(i) do return (self - i).to_i

redef fun finalize_once do val.finalize
end
```
lib/gmp/gmp.nit:120,1--287,3