manufacturing.yield-scrap
Whole units to start for a required good output at a process yield, and the scrap that allows for.
1.0.0 · published 2026-10-03 by charlie · Anterra
Pinned by 15 tests, run in TypeScript, Python and Rust.
What it does
How many units to start so that, at a process yield, enough good units come out:
input = ceil(requiredOutput / yield) scrap = input - requiredOutput
For example
inputForYield(100, 95%)→ input 106, scrap 6 100 good units at 95% need 105.26, so 106 starts and 6 allowed as scrapinputForYield(95, 95%)→ input 100, scrap 5 95 good units at 95% need exactly 100 startsinputForYield(563, 56.3%)→ input 1,000, scrap 437 563 good units at 56.3% need exactly 1000 starts; 563 / 0.563 in floating point is 1000.0000000000001, whose ceiling is 1001
The function
The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.
export function inputForYield(requiredOutput: number, yieldBasisPoints: number): YieldPlan
| requiredOutput | int | good units needed, not negative |
| yieldBasisPoints | int | good output as a share of input: 9500 = 95%, 1 to 10000 |
| returns | YieldPlan |
The type it declares, generated into your project
/** What to start and what the process is expected to lose. */
export interface YieldPlan {
/** units to start: the smallest whole number whose yield covers requiredOutput */
readonly input: number;
/** input minus requiredOutput: the units the yield allows to be lost */
readonly scrap: number;
}
Your code names it in one line, in the file that uses it
import { inputForYield } from "#fune/manufacturing.yield-scrap@^1";
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
import { roundDiv } from "./math_round_div.ts"; ← from math.round-div ^1.0.0 · built alongside by fune
import { type YieldPlan } from "./manufacturing_yield_scrap_types.ts";
const MAX_OUTPUT = Math.floor(Number.MAX_SAFE_INTEGER / 10000);
/**
* Starts needed for a good output at a yield, rounded up in integers so an
* exact answer (95 at 95% is 100) never becomes 101 through a float.
*/
export function inputForYield(requiredOutput: number, yieldBasisPoints: number): YieldPlan {
if (!Number.isInteger(requiredOutput) || requiredOutput < 0 || requiredOutput > MAX_OUTPUT) {
throw new RangeError(`requiredOutput must be a whole number of units from 0 to ${MAX_OUTPUT}, received ${requiredOutput}`);
}
if (!Number.isInteger(yieldBasisPoints) || yieldBasisPoints < 1 || yieldBasisPoints > 10000) {
throw new RangeError(`yieldBasisPoints must be a whole number from 1 to 10000, received ${yieldBasisPoints}`);
}
const input = roundDiv(requiredOutput * 10000, yieldBasisPoints, "up");
return { input, scrap: input - requiredOutput };
}Install
fune build
With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and its 1 dependency, pins them in fune.lock, downloads only the TypeScript package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:
fune add manufacturing.yield-scrap
The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./manufacturing.yield-scrap-1.0.0-typescript.fune, or fetch it from a terminal with fune pull manufacturing.yield-scrap@1.0.0:typescript.
The whole function, every language, is one file too: manufacturing.yield-scrap-1.0.0.fune, 9,473 bytes, sha256 ab5b9cd98e14ed85a740cf8e559162cb6e2553b2573427c955d5584c4f4351aa. It installs into a project of any language.
Customise it in your app
The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.
before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.
// fune: before manufacturing.yield-scrap
after — your function gets the result and the arguments, and returns the final result.
// fune: after manufacturing.yield-scrap
replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.
// fune: replace math.round-div in manufacturing.yield-scrap
step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show manufacturing.yield-scrap --steps.
// fune: step manufacturing.yield-scrap after <n|label>
Tests
A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.
| Case | Arguments | Expected | |
|---|---|---|---|
| 100 good units at 95% need 105.26, so 106 starts and 6 allowed as scrap | 100, 95% | → | input 106, scrap 6 |
| 95 good units at 95% need exactly 100 starts | 95, 95% | → | input 100, scrap 5 |
| 563 good units at 56.3% need exactly 1000 starts; 563 / 0.563 in floating point is 1000.0000000000001, whose ceiling is 1001 | 563, 56.3% | → | input 1,000, scrap 437 |
| 57 at 90% need 63.33, so 64 | 57, 90% | → | input 64, scrap 7 |
| a 100% yield needs no allowance | 250, 100% | → | input 250, scrap 0 |
| a tiny shortfall still costs a whole start: 1000 at 99.99% need 1000.1, so 1001 | 1,000, 99.99% | → | input 1,001, scrap 1 |
| one good unit at 30% needs 3.33, so 4 starts | 1, 30% | → | input 4, scrap 3 |
| the lowest yield, 0.01%: one good unit needs 10000 starts | 1, 0.01% | → | input 10,000, scrap 9,999 |
| zero output needs no input | 0, 80% | → | input 0, scrap 0 |
| a 50% yield doubles the input exactly | 37, 50% | → | input 74, scrap 37 |
Show the other 5 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| a zero yield is an error: nothing good ever comes out | 100, 0% | → | error: yieldBasisPoints must be a whole number from 1 to 10000 |
| a yield over 100% is an error | 100, 100.01% | → | error: yieldBasisPoints must be a whole number from 1 to 10000 |
| a negative output is an error | -5, 95% | → | error: requiredOutput must be a whole number of units |
| a fractional output is an error | 10.5, 95% | → | error: requiredOutput must be a whole number of units |
| a fractional yield is an error | 100, 95.005% | → | error: yieldBasisPoints must be a whole number from 1 to 10000 |
More from the author
With a 95% yield, 100 good units need 106 starts (105.26 rounded up), and the plan allows 6 to be scrapped.
**Rounded up, exactly.** You cannot start part of a unit, and rounding down would leave you short, so the input is always rounded up. The division is done in integers (`requiredOutput * 10000 / yieldBasisPoints`, rounded up by `math.round-div`), never as a float: 563 good units at a 56.3% yield need exactly 1000 starts, but `563 / 0.563` in floating point is 1000.0000000000001, and its ceiling is 1001.
**Scrap is the allowance.** At the stated yield, `input` starts are expected to give at least `requiredOutput` good units and fewer than `requiredOutput + 1` (the rounding never buys a whole extra unit), so `scrap` is the whole number of units the plan expects to lose. The actual scrap is whatever the process does on the day.
**Yield is in basis points**, 1 to 10000 (0.01% to 100%). A yield of 0 is an error: no number of starts gives any good output. A required output of 0 needs no input.
For a routing with several steps, apply this from the last step backwards: the input of one step is the required output of the one before, rounded up at each step, because each step has to start whole units.
Files
| Path | Bytes |
|---|---|
| README.md | 1,408 |
| impl/python.py | 1,163 |
| impl/rust.rs | 1,549 |
| impl/typescript.ts | 1,003 |
| vectors.json | 2,046 |