Skip to content

Type Alias: MathNode ​

ts
type MathNode = 
  | {
  kind: "dice";
  group: number;
}
  | {
  kind: "number";
  value: number;
}
  | {
  kind: "op";
  op: "+" | "-" | "*" | "/";
  left: MathNode;
  right: MathNode;
}
  | {
  kind: "call";
  name: MathFunction;
  args: MathNode[];
};

Defined in: src/math.ts:12

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.

Union Members ​

Type Literal ​

ts
{
  kind: "dice";
  group: number;
}

The total of one kind of dice: the roll's kind at this place, from 0.


Type Literal ​

ts
{
  kind: "number";
  value: number;
}

A whole number.


Type Literal ​

ts
{
  kind: "op";
  op: "+" | "-" | "*" | "/";
  left: MathNode;
  right: MathNode;
}

Two amounts added, taken away, multiplied or divided.


Type Literal ​

ts
{
  kind: "call";
  name: MathFunction;
  args: MathNode[];
}

A function of one amount (floor, ceil, round, abs) or of several (max, min).

MIT © John Morris