float
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.
Example
#3.14 \
#1e4 \
#(10 / 4)
Constructor
If a type has a constructor, you can call it like a function to create a new value of the type.
If a type has a constructor, you can call it like a function to create a new value of the type.
Converts a value to a float.
- Booleans are converted to
0.0
or1.0
. - Integers are converted to the closest 64-bit float.
- Ratios are divided by 100%.
- Strings are parsed in base 10 to the closest 64-bit float. Exponential notation is supported.
#float(false) \
#float(true) \
#float(4) \
#float(40%) \
#float("2.7") \
#float("1e5")
value
The value that should be converted to a float.
Definitions
Functions and types and can have associated definitions. These are accessed by specifying the function or type, followed by a period, and then the definition's name.
Functions and types and can have associated definitions. These are accessed by specifying the function or type, followed by a period, and then the definition's name.
is-nan
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.
self.is-nan() -> bool
View example
#float.is-nan(0) \
#float.is-nan(1) \
#float.is-nan(calc.nan)
is-infinite
Checks if a float is infinite.
For floats, there is positive and negative infinity. This function
returns true
if the float is either positive or negative infinity.
self.is-infinite() -> bool
View example
#float.is-infinite(0) \
#float.is-infinite(1) \
#float.is-infinite(calc.inf)
signum
Calculates the sign of a floating point number.
- If the number is positive (including
+0.0
), returns1.0
. - If the number is negative (including
-0.0
), returns-1.0
. - If the number is
calc.nan
, returnscalc.nan
.
self.signum() -> float
View example
#(5.0).signum() \
#(-5.0).signum() \
#(0.0).signum() \