diff --git a/src/__tests__/util.spec.ts b/src/__tests__/util.spec.ts index 01de8b7f..8a5a25ca 100644 --- a/src/__tests__/util.spec.ts +++ b/src/__tests__/util.spec.ts @@ -59,6 +59,18 @@ describe("Hertz formatter", () => { it("supports megahertz", () => { expect(formatHertz(123.456e6)).toBe("123.456MHz"); }); + + it("supports ronnahertz", () => { + expect(formatHertz(123.456e27)).toBe("123.456RHz"); + }); + + it("falls back to exponential format for unreasonably large frequencies", () => { + expect(formatHertz(1.23456e40)).toBe("1.235e+40Hz"); + }); + + it("zeros out with unreasonably small frequencies", () => { + expect(formatHertz(1.23456e-40)).toBe("0.000qHz"); + }); }); describe("Auto key color algorithm", () => { diff --git a/src/utils.ts b/src/utils.ts index 98d77ef3..0cadfdc9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -75,6 +75,12 @@ export function formatHertz(frequency: number, fractionDigits = 3) { } // Submultiples + if (magnitude < 1e-27) { + return (frequency * 1e30).toFixed(fractionDigits) + "qHz"; + } + if (magnitude < 1e-24) { + return (frequency * 1e27).toFixed(fractionDigits) + "rHz"; + } if (magnitude < 1e-21) { return (frequency * 1e24).toFixed(fractionDigits) + "yHz"; } @@ -101,11 +107,17 @@ export function formatHertz(frequency: number, fractionDigits = 3) { } // Too large. Use scientific notation. - if (magnitude > 1e28) { + if (magnitude > 1e34) { return formatExponential(frequency) + "Hz"; } // Multiples + if (magnitude > 1e30) { + return (frequency * 1e-30).toFixed(fractionDigits) + "QHz"; + } + if (magnitude > 1e27) { + return (frequency * 1e-27).toFixed(fractionDigits) + "RHz"; + } if (magnitude > 1e24) { return (frequency * 1e-24).toFixed(fractionDigits) + "YHz"; }