注意 当サイトは、Typst v0.12.0 公式ドキュメントを、日本語コミュニティが非公式に翻訳したものです。誤訳・未訳・古い情報が含まれている可能性があるため、公式ドキュメント との併用を推奨します。このサイトの内容に誤りを発見された方は、GitHubリポジトリまでご報告を頂けましたら幸いです。我々のコミュニティにご興味のある方は、ぜひ非公式Discordサーバー「くみはんクラブ」にご参加ください。
Warning: This site provides an unofficial translation of the Typst v0.12.0 documentation by the Japanese Community. Please note that there may be some inaccuracies, untranslated sections or outdated information. We highly recommend referring to the latest official documentation as well. If you find any errors in the content, please let us know through our GitHub repository. If you are interested in our community, feel free to join our unofficial Discord server, “Kumihan Club.”
Typst ドキュメント日本語版

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.

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

Example

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

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

#float(false) \
#float(true) \
#float(4) \
#float(40%) \
#float("2.7") \
#float("1e5")
Preview

value
bool int float ratio str decimal
RequiredPositional
Positional parameters are specified in order, without names.

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.

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(float.nan)
Preview

is-infinite

Checks if a float is infinite.

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

self.is-infinite(
) -> bool
View example
#float.is-infinite(0) \
#float.is-infinite(1) \
#float.is-infinite(float.inf)
Preview

signum

Calculates the sign of a floating point number.

self.signum(
) -> float
View example
#(5.0).signum() \
#(-5.0).signum() \
#(0.0).signum() \
#float.nan.signum()
Preview

from-bytes

Converts bytes to a float.

float.from-bytes() -> float
View example
#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")
Preview

bytes
bytes
RequiredPositional
Positional parameters are specified in order, without names.

The bytes that should be converted to a float.

Must be of length exactly 8 so that the result fits into a 64-bit float.

endian
str

The endianness of the conversion.

Default:"little"

to-bytes

Converts a float to bytes.

self.to-bytes() -> bytes
View example
#array(1.0.to-bytes(endian: "big")) \
#array(1.0.to-bytes())
Preview

endian
str

The endianness of the conversion.

Default:"little"