MathNode型
リファレンスの説明と例は英語です。見出しと目次は日本語です。
Arithmetic over the kinds of dice in a roll: (2d6+3)*2, 1d20-1d4,
floor(4d6/2), max(1d6,1d8). A roll with a formula still throws its
kinds of dice in order, exactly as it would without one; the formula is
only how their totals are put together.
Everything is worked out in whole-number fractions, never in floating
point, so floor(7/3*3) is 7 and not 6 or 8, in a roll and in its odds
alike. A formula must come to a whole number: a division has to be rounded
(floor, ceil or round) before it reaches the total.
インポート
import type { MathNode } from "@johnmorrisdotca/korokoro";
定義
type MathNode = {
kind: "dice";
group: number;
} | {
kind: "number";
value: number;
} | {
kind: "op";
op: "+" | "-" | "*" | "/";
left: MathNode;
right: MathNode;
} | {
kind: "call";
name: MathFunction;
args: MathNode[];
};
例
import type { MathNode } from "@johnmorrisdotca/korokoro";
const value: MathNode = { kind: "dice", group: 0 };
console.log(value.kind);dice出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。