Helios language/ Builtins/

Int

This is an unbounded integer (like Haskell's Integer type).

Associated functions

from_base58

Decodes a String representing a base58 encoded Int.

Throws an error if the string contains an invalid character.

Int::from_base58(encoded: String) -> Int

from_big_endian

Converts a ByteArray into an Int. The last byte is multiplied by 1 before adding to the sum, the second-to-last byte is multiplied by 256 etc.

The returned Int is always positive.

Int::from_big_endian(bytes: ByteArray) -> Int

from_data

Int::from_data(data: Data) -> Int

from_little_endian

Converts a ByteArray into an Int. The first byte is multiplied by 1 before adding to the sum, the second byte is multiplied by 256 etc.

The returned Int is always positive.

Int::from_little_endian(bytes: ByteArray) -> Int

max

Returns the greater of two numbers.

Int::max(a: Int, b: Int) -> Int

min

Returns the lesser of two numbers.

Int::min(a: Int, b: Int) -> Int

parse

Parses a string representation of an integer of the form ((-)?[1-9][0-9]*)|0 (i.e. a non zero-padded integer). Throws an error if the string representation of the integer doesn't respect this format. Note that -0 isn't allowed, so zeros can only be represented by a single 0 digit.

Int::parse(string: String) -> Int

sqrt

Calculates the square root of an integer. The result is truncated if it can't be represented by a whole number. Throws an error if the input number is negative.

Int::sqrt(a: Int) -> Int

Operators

==

Int == Int -> Bool

!=

Int != Int -> Bool

>=

Int >= Int -> Bool

>

Int > Int -> Bool

<=

Int <= Int -> Bool

<

Int < Int -> Bool

+

Int + Int -> Int

-

Int - Int -> Int

*

Int * Int -> Int

/

Int / Int -> Int

%

Modulo operator that returns the remainder after division.

Int % Int -> Int

Methods

abs

Removes the sign, returning a positive Int.

int.abs() -> Int

bound

Bounds an Int if it falls outside a range. This builtin function doesn't check if the range is sensible.

int.bound(low: Int, high: Int) -> Int

bound_min

Bounds an Int to be greater or equals to a given minimum value.

int.bound_min(low: Int) -> Int

bound_max

Bounds an Int to be less or equals to a given maximum value.

int.bound_max(high: Int) -> Int

decode_zigzag

Decodes a zigzag encoded Int. Throws an error if the Int is negative.

unsigned_int.decode_zigzag() -> Int

encode_zigzag

Applies zigzag encoding to the Int, returning a positive Int.

signed_int.encode_zigzag() -> Int

serialize

int.serialize() -> ByteArray

show

Returns decimal representation of integer.

int.show() -> String

to_base58

Encodes the Int as a base58 String.

Throws an error if the Int is negative.

int.to_base58() -> String

to_big_endian

Encodes the Int as a big endian ByteArray.

Throws an error if the Int is negative.

int.to_big_endian() -> ByteArray

to_bool

Turns 0 into false, and any other integer into true.

int.to_bool() -> Bool

to_little_endian

Encodes the Int as a little endian ByteArray.

Throws an error if the Int is negative.

int.to_little_endian() -> ByteArray

to_hex

Returns the hexadecimal representation of the Int.

int.to_hex() -> String

to_real

Converts the Int to the fixed point Real representation.

int.to_real() -> Real