Alpha: this compiler is under active development and updates will break your projects. Not recommended for real use yet.
Skip to content

Fixed-point numbers ​

A scaled score stores a fraction as an integer: .scaled(Unit.MM) keeps three decimal places, and you read and write it in real units.

ts
const speed = work.score(ScoreTarget("speed")).scaled(Unit.MM); // millimetres: 1000 per block
speed.set(0.5); // stored as 500
UnitPer real unitFor
DM / CM / MM10 / 100 / 1000lengths, per block
THOUSANDTHS / TEN_THOUSANDTHS / HUNDRED_THOUSANDTHS1000 / 10^4 / 10^5values with no unit

Any other number works too, e.g. .scaled(100).

WriteDoes
speed.set(1.25) / .add(0.5)set / add a real value
math`${a} / ${b}`.into(out)any formula in real units, rounded into out
math`${v} * 0.98`.into(v)literals are real values too
speed.atLeast(2)compare against real values

Divide without losing precision ​

Scales are converted for you, so a small value over a large one doesn't floor to zero.

ts
import { Datapack, v26_3, ScoreTarget, Unit, math } from "helix";

const dp = new Datapack("physics", v26_3);
const work = dp.objective("work");
const dist = work.score(ScoreTarget("dist")).scaled(Unit.MM);
const time = work.score(ScoreTarget("time")).scaled(Unit.MM);
const speed = work.score(ScoreTarget("speed")).scaled(Unit.MM);

dp.createFunction("tick").build(() => {
  math`${dist} / ${time}`.into(speed);
});

Open in playground

Compiled output - the real files helix emits for the code above:

txt
execute store result score speed work run compute default integer {"type":"from_float","input":{"type":"round","input":{"type":"mul","inputs":[{"type":"div","left":{"type":"from_int","input":{"type":"score","target":{"type":"fixed","name":"dist"},"score":"work"}},"right":{"type":"from_int","input":{"type":"score","target":{"type":"fixed","name":"time"},"score":"work"}}},1000]}}}
json
{
  "values": [
    "physics:tick"
  ]
}
txt
{
  "pack": {
    "description": "physics\nCreated using Helix",
    "min_format": [
      121,
      0
    ],
    "max_format": [
      121,
      0
    ]
  }
}

TIP

Same-scale + - min max abs stays scoreboard maths. Anything else runs through /compute, so it needs 26.3.

Below 26.3: Fixed ​

Fixed does the same job with scoreboard operations only.

ts
const dist = new Fixed(work.score(ScoreTarget("dist")), 1000);
dist.divide(time); // multiplies by the scale first
MethodDoes
.assign / .add / .subcopy / += / -= at the same scale
.mul(other) / .divide()multiply / divide, scale kept
.gain(k) / .reduce(k)multiply / divide by a unitless score
.negate() / .clamp()*= -1 / clamp into [lo, hi]

Pass a third argument, a score set to the scale at load, to save one command per mul/divide.

See also ​

Released under the MIT License · Credits
These docs were written with AI; the layout and every page have been reviewed by a human.