情報アイコン
情報 / Info
当サイトは、Typst GmbHの許諾を得て、日本語コミュニティ「Typst Japan Community」がTypst v0.13.1の公式ドキュメントを翻訳したものです。誤訳や古い情報が含まれている可能性があるため、公式ドキュメントとの併用を推奨します。翻訳の改善やサイトの機能向上について、GitHubでのIssueやPull Requestを歓迎します。コミュニティにご興味のある方はDiscordサーバー「くみはんクラブ」にぜひご参加ください。
This site provides a Japanese translation of the Typst v0.13.1 documentation maintained by the "Typst Japan Community" with permission from Typst GmbH. We recommend using this alongside the official documentation. We welcome contributions through Issues and Pull Requests on our GitHub repository for both translation improvements and website enhancements. Feel free to join our Discord server "Kumihan Club".
言語アイコン
未翻訳

このページはまだ翻訳されていません。原文の内容が表示されています。

int

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

#(1 + 2) \
#(2 - 5) \
#(3 + 4 < 8)

#0xff \
#0o10 \
#0b1001
Preview

コンストラクタ
ヘルプアイコン

Converts a value to an integer. Raises an error if there is an attempt to produce an integer larger than the maximum 64-bit signed integer or smaller than the minimum 64-bit signed integer.

  • Booleans are converted to 0 or 1.
  • Floats and decimals are truncated to the next 64-bit integer.
  • Strings are parsed in base 10.
#int(false) \
#int(true) \
#int(2.7) \
#int(decimal("3.8")) \
#(int("27") + int("4"))
Preview

value
Required
ヘルプアイコン
Positional
ヘルプアイコン

The value that should be converted to an integer.

定義
ヘルプアイコン

signum

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.
self.signum(
)->
右矢印アイコン
例を表示
#(5).signum() \
#(-5).signum() \
#(0).signum()
Preview

bit-not

Calculates the bitwise NOT of an integer.

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

self.bit-not(
)->
右矢印アイコン
例を表示
#4.bit-not() \
#(-1).bit-not()
Preview

bit-and

Calculates the bitwise AND between two integers.

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

self.bit-and()->
右矢印アイコン
例を表示
#128.bit-and(192)
Preview

rhs
Required
ヘルプアイコン
Positional
ヘルプアイコン

The right-hand operand of the bitwise AND.

bit-or

Calculates the bitwise OR between two integers.

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

self.bit-or()->
右矢印アイコン
例を表示
#64.bit-or(32)
Preview

rhs
Required
ヘルプアイコン
Positional
ヘルプアイコン

The right-hand operand of the bitwise OR.

bit-xor

Calculates the bitwise XOR between two integers.

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

self.bit-xor()->
右矢印アイコン
例を表示
#64.bit-xor(96)
Preview

rhs
Required
ヘルプアイコン
Positional
ヘルプアイコン

The right-hand operand of the bitwise XOR.

bit-lshift

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.

self.bit-lshift()->
右矢印アイコン
例を表示
#33.bit-lshift(2) \
#(-1).bit-lshift(3)
Preview

shift
Required
ヘルプアイコン
Positional
ヘルプアイコン

The amount of bits to shift. Must not be negative.

bit-rshift

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.

self.bit-rshift()->
右矢印アイコン
例を表示
#64.bit-rshift(2) \
#(-8).bit-rshift(2) \
#(-8).bit-rshift(2, logical: true)
Preview

shift
Required
ヘルプアイコン
Positional
ヘルプアイコン

The amount of bits to shift. Must not be negative.

Shifts larger than 63 are allowed and will cause the return value to saturate. For non-negative numbers, the return value saturates at 0, while, for negative numbers, it saturates at -1 if logical is set to false, or 0 if it is true. This behavior is consistent with just applying this operation multiple times. Therefore, the shift will always succeed.

logical

Toggles whether a logical (unsigned) right shift should be performed instead of arithmetic right shift. If this is true, negative operands will not preserve their sign bit, and bits which appear to the left after the shift will be 0. This parameter has no effect on non-negative operands.

デフォルト値:

false

from-bytes

Converts bytes to an integer.

int.from-bytes()->
右矢印アイコン
例を表示
#int.from-bytes(bytes((0, 0, 0, 0, 0, 0, 0, 1))) \
#int.from-bytes(bytes((1, 0, 0, 0, 0, 0, 0, 0)), endian: "big")
Preview

bytes
Required
ヘルプアイコン
Positional
ヘルプアイコン

The bytes that should be converted to an integer.

Must be of length at most 8 so that the result fits into a 64-bit signed integer.

endian

The endianness of the conversion.

使用可能な文字列値:
  • 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.

デフォルト値:

"little"

signed

Whether the bytes should be treated as a signed integer. If this is true and the most significant bit is set, the resulting number will negative.

デフォルト値:

true

to-bytes

Converts an integer to bytes.

self.to-bytes()->
右矢印アイコン
例を表示
#array(10000.to-bytes(endian: "big")) \
#array(10000.to-bytes(size: 4))
Preview

endian

The endianness of the conversion.

使用可能な文字列値:
  • 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.

デフォルト値:

"little"

size

The size in bytes of the resulting bytes (must be at least zero). If the integer is too large to fit in the specified size, the conversion will truncate the remaining bytes based on the endianness. To keep the same resulting value, if the endianness is big-endian, the truncation will happen at the rightmost bytes. Otherwise, if the endianness is little-endian, the truncation will happen at the leftmost bytes.

Be aware that if the integer is negative and the size is not enough to make the number fit, when passing the resulting bytes to int.from-bytes, the resulting number might be positive, as the most significant bit might not be set to 1.

デフォルト値:

8

検索