Typst Fumadocs

Float

Documentation for the Float type.

A floating-point number.

A limited-precision representation of a real number. Typst uses 64 bits to store floats. Wherever a float is expected, you can also pass an integer.

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

NaN and positive infinity are available as float.nan and float.inf respectively.

Example

Loading compiler...

Constructor

Converts a value to a float.

  • Booleans are converted to 0.0 or 1.0.
  • Integers are converted to the closest 64-bit float. For integers with absolute value less than calc.pow(2, 53), this conversion is exact.
  • Ratios are divided by 100%.
  • Strings are parsed in base 10 to the closest 64-bit float. Exponential notation is supported.
Loading compiler...
#float(
  value
) -> float

Parameters

Prop

Type

Methods

Checks if a float is not a number.

In IEEE 754, more than one bit pattern represents a NaN. This function returns true if the float is any of those bit patterns.

Loading compiler...

Checks if a float is infinite.

Floats can represent positive infinity and negative infinity. This function returns true if the float is an infinity.

Loading compiler...

Calculates the sign of a floating point number.

  • If the number is positive (including +0.0), returns 1.0.
  • If the number is negative (including -0.0), returns -1.0.
  • If the number is NaN, returns float.nan.
Loading compiler...

Interprets bytes as a float.

Loading compiler...
#float.from-bytes(
  bytes,
  endian: str
) -> float

Parameters

Prop

Type

Converts a float to bytes.

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

Parameters

Prop

Type

On this page