Typst Fumadocs

Integer

Documentation for the Integer type.

A whole number.

The number can be negative, zero, or positive. As Typst uses 64 bits to store integers, integers cannot be smaller than -9223372036854775808 or larger than 9223372036854775807. Integer literals are always positive, so a negative integer such as -1 is semantically the negation - of the positive literal 1. A positive integer greater than the maximum value and a negative integer less than or equal to the minimum value cannot be represented as an integer literal, and are instead parsed as a float. The minimum integer value can still be obtained through integer arithmetic.

The number can also be specified as hexadecimal, octal, or binary by starting it with a zero followed by either x, o, or b.

You can convert a value to an integer with this type's constructor.

Example

Loading compiler...

Constructor

Converts a value to an integer. Raises an error if there is an attempt to parse an invalid string or produce an integer that doesn't fit into a 64-bit signed integer.

  • Booleans are converted to 0 or 1.
  • Floats and decimals are rounded to the next 64-bit integer towards zero.
  • Strings are parsed in base 10 by default.
Loading compiler...
#int(
  value,
  base: int
) -> int

Parameters

Prop

Type

Methods

Calculates the sign of an integer.

  • If the number is positive, returns 1.
  • If the number is negative, returns -1.
  • If the number is zero, returns 0.
Loading compiler...

Calculates the bitwise NOT of an integer.

For the purposes of this function, the operand is treated as a signed integer of 64 bits.

Loading compiler...

Calculates the bitwise AND between two integers.

For the purposes of this function, the operands are treated as signed integers of 64 bits.

Loading compiler...
#int.bit-and(
  rhs
) -> int

Parameters

Prop

Type

Calculates the bitwise OR between two integers.

For the purposes of this function, the operands are treated as signed integers of 64 bits.

Loading compiler...
#int.bit-or(
  rhs
) -> int

Parameters

Prop

Type

Calculates the bitwise XOR between two integers.

For the purposes of this function, the operands are treated as signed integers of 64 bits.

Loading compiler...
#int.bit-xor(
  rhs
) -> int

Parameters

Prop

Type

Shifts the operand's bits to the left by the specified amount.

For the purposes of this function, the operand is treated as a signed integer of 64 bits. An error will occur if the result is too large to fit in a 64-bit integer.

Loading compiler...
#int.bit-lshift(
  shift
) -> int

Parameters

Prop

Type

Shifts the operand's bits to the right by the specified amount. Performs an arithmetic shift by default (extends the sign bit to the left, such that negative numbers stay negative), but that can be changed by the logical parameter.

For the purposes of this function, the operand is treated as a signed integer of 64 bits.

Loading compiler...
#int.bit-rshift(
  shift,
  logical: bool
) -> int

Parameters

Prop

Type

Converts bytes to an integer.

Loading compiler...
#int.from-bytes(
  bytes,
  endian: str,
  signed: bool
) -> int

Parameters

Prop

Type

Converts an integer to bytes.

Loading compiler...
#int.to-bytes(
  endian: str,
  size: int
) -> bytes

Parameters

Prop

Type

On this page