The Machines · Runtime stack

seedmath

A reckoner seed: math's geometry and interpolation words — machines/seeds/seedmath.shoddy

the seedmath machine's icon

Summary

seedmath is a seed: a small file that plugs one machine's words — its named commands — into the reckoner calculator. It bridges the geometry, interpolation and logarithm words math adds on top of the reckoner engine core's own trig and logs: LOGB LOG2 HYPOT DIST CLAMP LERP REMAP ROUNDTO. (Interpolation is finding a value part-way between two known ones.) Its whole public surface is one function. Fold RckSeedMath over a state, and all eight words are in the dictionary.

Not bridged: Rad and Deg. The engine core already owns DEG/RAD as the angle mode. Bridging math's value-returning versions here would give two spellings for one idea — and the wrong one would be the one that gets used by habit.

Why It's Useful

Every word here checks its inputs first: it pre-flights the division or logarithm math's plain / and Log would otherwise abort on (an abort ends the whole session). This is R4.1 applied to a machine written before the no-abort contract existed, so math carries none of its own guards. LOGB refuses a non-positive x or a base of one before either reaches a division. REMAP refuses an input range of zero width before Remap's own division sees it. The guard is duplicated here rather than retrofitted into math.shoddy itself. That duplication is the price paid once per seed for a language with no catchable errors (see reckoner's guide).

User's Guide

Let st0 = RckSeedMath(RckNew())
RckEval(st0, "3 4 5 12 DIST")            ' x: 13
RckEval(st0, "5 0 10 CLAMP")             ' x: 5
RckEval(st0, "0 100 3 LERP")             ' x: 300

LOGB takes the base first, matching how it reads aloud — "log base 2 of 8":

RckEval(st0, "2 8 LOGB")                 ' x: 3

Word Reference

WordDescription
LOGB ( base x -- log )Logarithm of x to the given base. Refuses x at or below zero, and a base that is zero or below or equal to one.
LOG2 ( x -- log2 x )Logarithm base two; refuses zero and below.
HYPOT ( x y -- h )The length of the hypotenuse of a right triangle with legs x and y.
DIST ( x0 y0 x1 y1 -- d )The distance between two points.
CLAMP ( x lo hi -- y )x held between lo and hi.
LERP ( a b t -- y )Linear interpolation between a and b at fraction t.
REMAP ( x inLo inHi outLo outHi -- y )Map x from one range onto another, linearly; refuses an input range with two equal ends.
ROUNDTO ( x n -- y )x rounded to n decimal places; refuses a place count wider than 15.

Who Uses It

UserHow
halifaxThe geometry and interpolation words on the calculator's dictionary: HYPOT, DIST, CLAMP, LERP, REMAP, ROUNDTO and the extra logarithms.
sparkySparky folds it too, so a model calling eval reaches the same words halifax puts at a prompt.

A mill — a complete Shoddy program — claims this seed by folding RckSeedMath over its reckoner state. That is all halifax does.

The Machines It Uses

MachineWhy
cuttleThe Cell type every bridged word reads its arguments from and answers into.
mathThe domain this seed bridges: Hypot, Dist, Clamp, Lerp, Remap, Log2, LogBase and RoundTo.
reckonerRckReg, RckSeeding and the argument readers every registered word is built from.
seqList plumbing under the multi-argument reader that pulls several numbers off the stack at once.