integer.l0

integer.l0

Module: std.integer

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

Imports / Includes

  • std.assert

Symbols

Function int_max

1
func int_max() -> int

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

Returns: INT_MAX.

Function int_min

1
func int_min() -> int

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

Returns: INT_MIN.

Function checked_add_int

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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

1
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.