compiler/shared/l0/stdlib/std/integer.l0

Module std.integer

Overview Symbols grouped by source file: compiler/shared/l0/stdlib/std/integer.l0

Module: std.integer

Source: compiler/shared/l0/stdlib/std/integer.l0 Language: Dea/L0

Imports / Includes

  • std.assert

Symbols

Function int_max

func int_max() -> int

Returns the maximum value for a 32-bit signed integer.

Returns: INT_MAX.

Function int_min

func int_min() -> int

Returns the minimum value for a 32-bit signed integer.

Returns: INT_MIN.

Function checked_add_int

func checked_add_int(a: int, b: int) -> int?

Performs checked integer addition.

Parameters:

  • a: The first operand.
  • b: The second operand.

Returns: The sum, or null on overflow.

Function checked_sub_int

func checked_sub_int(a: int, b: int) -> int?

Performs checked integer subtraction.

Parameters:

  • a: The first operand.
  • b: The second operand.

Returns: The difference, or null on overflow.

Function checked_mul_int

func checked_mul_int(a: int, b: int) -> int?

Performs checked integer multiplication.

Parameters:

  • a: The first operand.
  • b: The second operand.

Returns: The product, or null on overflow.

Function emod

func emod(a: int, b: int) -> int

Calculates the Euclidean modulo: always returns a non-negative result, even if a is negative.

Requires b > 0 .

Parameters:

  • a: The dividend.
  • b: The divisor (must be > 0).

Returns: The non-negative remainder.

Function ediv

func ediv(a: int, b: int) -> int

Calculates the Euclidean quotient paired with emod .

Parameters:

  • a: The dividend.
  • b: The divisor (must be > 0).

Returns: The Euclidean quotient.

Function div_floor

func div_floor(a: int, b: int) -> int

Calculates the mathematical floor of a / b .

The quotient must be representable as int .

Parameters:

  • a: The dividend.
  • b: The divisor (must be non-zero).

Returns: The floor quotient.

Function div_ceil

func div_ceil(a: int, b: int) -> int

Calculates the mathematical ceiling of a / b .

The quotient must be representable as int .

Parameters:

  • a: The dividend.
  • b: The divisor (must be non-zero).

Returns: The ceiling quotient.

Function min

func min(a: int, b: int) -> int

Returns the smaller of two integers.

Parameters:

  • a: The first operand.
  • b: The second operand.

Returns: The minimum value.

Function max

func max(a: int, b: int) -> int

Returns the larger of two integers.

Parameters:

  • a: The first operand.
  • b: The second operand.

Returns: The maximum value.

Function clamp

func clamp(x: int, lo: int, hi: int) -> int

Clamps x into the closed interval [lo, hi] .

Parameters:

  • x: The value to clamp.
  • lo: The lower bound.
  • hi: The upper bound.

Returns: The clamped value.

Function sign

func sign(x: int) -> int

Returns the sign of x as -1 , 0 , or 1 .

Parameters:

  • x: The input value.

Returns: The sign indicator.

Function is_even

func is_even(x: int) -> bool

Returns whether x is even.

Parameters:

  • x: The input value.

Returns: True when x is evenly divisible by 2.

Function is_odd

func is_odd(x: int) -> bool

Returns whether x is odd.

Parameters:

  • x: The input value.

Returns: True when x is not evenly divisible by 2.

Function is_multiple

func is_multiple(a: int, b: int) -> bool

Returns whether a is a multiple of b .

Parameters:

  • a: The dividend.
  • b: The divisor (must be non-zero).

Returns: True when a is evenly divisible by b.

Function abs

func abs(x: int) -> int?

Returns the absolute value of x .

Parameters:

  • x: The input value.

Returns: The absolute value, or null when it is not representable as int.

Function gcd

func gcd(a: int, b: int) -> int?

Returns the non-negative greatest common divisor of a and b .

Parameters:

  • a: The first operand.
  • b: The second operand.

Returns: The greatest common divisor, or null when it is not representable as int.

Function lcm

func lcm(a: int, b: int) -> int?

Returns the non-negative least common multiple of a and b .

Parameters:

  • a: The first operand.
  • b: The second operand.

Returns: The least common multiple, or null when it is not representable as int.

Function pow

func pow(base: int, exp: int) -> int?

Returns base raised to the non-negative exponent exp .

Parameters:

  • base: The base value.
  • exp: The exponent.

Returns: The result, or null when exp < 0 or the result is not representable as int.

Function isqrt

func isqrt(x: int) -> int?

Returns the floor integer square root of x .

Parameters:

  • x: The input value.

Returns: The floor square root, or null when x < 0.

Function align_down

func align_down(x: int, align: int) -> int?

Rounds x down to the nearest multiple of align .

Parameters:

  • x: The input value.
  • align: The positive alignment.

Returns: The aligned value, or null when the mathematical result is not representable as int.

Function align_up

func align_up(x: int, align: int) -> int?

Rounds x up to the nearest multiple of align .

Parameters:

  • x: The input value.
  • align: The positive alignment.

Returns: The aligned value, or null when the mathematical result is not representable as int.

Function is_aligned

func is_aligned(x: int, align: int) -> bool

Returns whether x is already aligned to align .

Parameters:

  • x: The input value.
  • align: The positive alignment.

Returns: True when x is a multiple of align.