Skip to content

helix / Fixed

Class: Fixed

Defined in: core/frontend/nodes/fixed.ts:24

A fixed-point scalar: one integer Score that stands for a fractional value, encoded as realValue × scale. Minecraft scoreboards are integer-only, so fractions are carried by a fixed scale factor - and every multiply/divide has to rebalance it. Multiply two scaled values and the scale squares; divide and the fraction is floored away. Fixed makes that bookkeeping part of the type and the method names instead of a comment you have to keep in your head.

Why a scale Score and not just a number. A scoreboard players operation operand must itself be a score - you can't *= 1000 against a literal. So a Fixed that wants to multiply or divide by its own scale carries scaleScore, a slot seeded once at load to scale (e.g. ctx.scoreSet(scaleScore.set(1000))). The plain number scale is kept alongside for reasoning and asserts. Ops that don't touch the scale (assign/add/sub/negate/gain/reduce/clamp) need no scaleScore; mul and divide do.

Like Score/ScoreVec3 it holds a reference to an existing slot and allocates nothing, emits into the ambient context (pass ctx to override), and chains by returning this. Division floors toward −∞ (integer scoreboard divide).

Constructors

Constructor

new Fixed(score, scale, scaleScore?): Fixed

Defined in: core/frontend/nodes/fixed.ts:25

Parameters

score

Score

scale

number

scaleScore?

Score

Returns

Fixed

Properties

scale

readonly scale: number

Defined in: core/frontend/nodes/fixed.ts:27


scaleScore?

readonly optional scaleScore?: Score

Defined in: core/frontend/nodes/fixed.ts:28


score

readonly score: Score

Defined in: core/frontend/nodes/fixed.ts:26

Methods

add()

add(other, ctx?): this

Defined in: core/frontend/nodes/fixed.ts:50

this += other - same-scale addition is just integer +=.

Parameters

other

Score | Fixed

ctx?

FunctionContext

Returns

this


assign()

assign(other, ctx?): this

Defined in: core/frontend/nodes/fixed.ts:44

this = other (same scale; other may be a raw Score already at this scale).

Parameters

other

Score | Fixed

ctx?

FunctionContext

Returns

this


clamp()

clamp(lo, hi, ctx?): this

Defined in: core/frontend/nodes/fixed.ts:111

Clamp the underlying score into [lo, hi] (< hi then > lo).

Parameters

lo

Score

hi

Score

ctx?

FunctionContext

Returns

this


divide()

divide(divisor, ctx?): this

Defined in: core/frontend/nodes/fixed.ts:89

Fixed-point divide by divisor, precision-preserving: pre-multiplies by the scale so the integer /= keeps scale fractional bits - (a·scale)·scale / divisor lands the quotient back at this scale instead of flooring to 0. This is the operation that defuses the classic “small numerator ÷ large divisor truncates to zero, the value silently vanishes” scoreboard bug. Emits *= scale ; /= divisor. divisor is any Score/Fixed. (Needs scaleScore.)

Parameters

divisor

Score | Fixed

ctx?

FunctionContext

Returns

this


gain()

gain(k, ctx?): this

Defined in: core/frontend/nodes/fixed.ts:95

Multiply by a unitless factor k (*= k); the scale is unchanged.

Parameters

k

Score

ctx?

FunctionContext

Returns

this


mul()

mul(other, ctx?): this

Defined in: core/frontend/nodes/fixed.ts:76

Fixed-point multiply by a same-scale other: (a·scale)(b·scale) would be (ab)·scale², so we divide the scale back out to stay at this scale. Emits *= other ; /= scale. (Needs scaleScore.)

Parameters

other

Fixed

ctx?

FunctionContext

Returns

this


negate()

negate(negOne, ctx?): this

Defined in: core/frontend/nodes/fixed.ts:66

Negate in place (*= -1). Scoreboards have no unary minus, so this multiplies by a caller-owned -1 slot - clearer at the call site than spelling out the times(negOne) every time.

Parameters

negOne

Score

ctx?

FunctionContext

Returns

this


reduce()

reduce(k, ctx?): this

Defined in: core/frontend/nodes/fixed.ts:105

Divide by a unitless integer factor k (/= k); the scale is unchanged. Unlike divide this is a plain floor divide - use it for a gain/ratio constant (e.g. a stiffness divisor), not for dividing by another measured value.

Parameters

k

Score

ctx?

FunctionContext

Returns

this


sub()

sub(other, ctx?): this

Defined in: core/frontend/nodes/fixed.ts:56

this -= other - same-scale subtraction is just integer -=.

Parameters

other

Score | Fixed

ctx?

FunctionContext

Returns

this

Released under the MIT License · Credits