oncodsl / web /lib /fmt.ts
govindbalki's picture
Upload folder using huggingface_hub
0fff343 verified
Raw
History Blame Contribute Delete
604 Bytes
/**
* Format a fitness / score value. Returns "—" for null, undefined, NaN,
* or +/-Infinity so the UI never throws on degenerate programs.
*/
export function fmtFit(x: number | null | undefined, digits = 2): string {
if (typeof x === "number" && Number.isFinite(x)) return x.toFixed(digits);
return "—";
}
/** Numeric value to use for sort / colour when the raw fitness isn't
* finite. Pushes degenerate programs to the bottom of any ranking. */
export function fitnessForOrder(x: number | null | undefined): number {
return typeof x === "number" && Number.isFinite(x) ? x : -Infinity;
}