A reckoner seed: math's geometry and interpolation words — machines/seeds/seedmath.shoddy
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.
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).
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 | Description |
|---|---|
| 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. |
| User | How | |
|---|---|---|
| halifax | The geometry and interpolation words on the calculator's dictionary: HYPOT, DIST, CLAMP, LERP, REMAP, ROUNDTO and the extra logarithms. | |
| sparky | Sparky 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.
| Machine | Why | |
|---|---|---|
| cuttle | The Cell type every bridged word reads its arguments from and answers into. | |
| math | The domain this seed bridges: Hypot, Dist, Clamp, Lerp, Remap, Log2, LogBase and RoundTo. | |
| reckoner | RckReg, RckSeeding and the argument readers every registered word is built from. | |
| seq | List plumbing under the multi-argument reader that pulls several numbers off the stack at once. |