Development build 586e1bd4
Typst文档简体中文版v0.15.1 + dev 586e1bd4

float自始可用Go to source

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

#3.14 \ #1e4 \ #(10 / 4)

构造函数
Question mark
自始可用Go to source

Converts a value to a float.

Expand展开示例
#float(false) \ #float(true) \ #float(4) \ #float(40%) \ #float("2.7") \ #float("1e5")

value
bool or int or float or ratio or decimal or str
必需参数
Question mark
位置参数
Question mark

The value that should be converted to a float.

定义
Question mark

is-nan0.11.0起可用Go to source

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.

Expand展开示例
#float.is-nan(0) \ #float.is-nan(1) \ #float.is-nan(float.nan)
self.is-nan() → bool

is-infinite0.11.0起可用Go to source

Checks if a float is infinite.

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

Expand展开示例
#float.is-infinite(0) \ #float.is-infinite(1) \ #float.is-infinite(float.inf)
self.is-infinite() → bool

signum0.11.0起可用Go to source

Calculates the sign of a floating point number.

Expand展开示例
#(5.0).signum() \ #(-5.0).signum() \ #(0.0).signum() \ #float.nan.signum()
self.signum() → float

from-bytes0.12.0起可用Go to source

Interprets bytes as a float.

Expand展开示例
#float.from-bytes(bytes((0, 0, 0, 0, 0, 0, 240, 63))) \ #float.from-bytes(bytes((63, 240, 0, 0, 0, 0, 0, 0)), endian: "big")
float.from-bytes() → float

bytes
bytes
必需参数
Question mark
位置参数
Question mark

The bytes that should be converted to a float.

Must have a length of either 4 or 8. The bytes are then interpreted in IEEE 754′s binary32 (single-precision) or binary64 (double-precision) format depending on the length of the bytes.

endian默认值:"little"

The endianness of the conversion.

VariantDetails
"big"Big-endian byte order: The highest-value byte is at the beginning of the bytes.
"little"Little-endian byte order: The lowest-value byte is at the beginning of the bytes.

to-bytes0.12.0起可用Go to source

Converts a float to bytes.

Expand展开示例
#array(1.0.to-bytes(endian: "big")) \ #array(1.0.to-bytes())
self.to-bytes() → bytes

endian默认值:"little"

The endianness of the conversion.

VariantDetails
"big"Big-endian byte order: The highest-value byte is at the beginning of the bytes.
"little"Little-endian byte order: The lowest-value byte is at the beginning of the bytes.

size默认值:8

The size of the resulting bytes.

This must be either 4 or 8. The call will return the representation of this float in either IEEE 754′s binary32 (single-precision) or binary64 (double-precision) format depending on the provided size.