From 1c8d0c4ef5d4a8a2d2e01c8039308049d33e1b2d Mon Sep 17 00:00:00 2001 From: Denis Chevalier Date: Mon, 10 Aug 2026 09:39:23 +0200 Subject: Add assertion to check the maths early on, and fix typos --- lib/apply_prefix.typ | 12 ++++++++++++ lib/assert_aeq.typ | 3 +++ 2 files changed, 15 insertions(+) create mode 100644 lib/apply_prefix.typ create mode 100644 lib/assert_aeq.typ (limited to 'lib') diff --git a/lib/apply_prefix.typ b/lib/apply_prefix.typ new file mode 100644 index 0000000..f6bbfb7 --- /dev/null +++ b/lib/apply_prefix.typ @@ -0,0 +1,12 @@ +#let apply-prefix(value, prefix) = { + if prefix == "tera" { return value * calc.pow(10, 12) } + if prefix == "giga" { return value * calc.pow(10, 9) } + if prefix == "mega" { return value * calc.pow(10, 6) } + if prefix == "kilo" { return value * calc.pow(10, 3) } + if prefix == "milli" { return value * calc.pow(10, -3) } + if prefix == "micro" { return value * calc.pow(10, -6) } + if prefix == "nano" { return value * calc.pow(10, -9) } + if prefix == "pico" { return value * calc.pow(10, -12) } + if prefix == "femto" { return value * calc.pow(10, -15) } + return value +} diff --git a/lib/assert_aeq.typ b/lib/assert_aeq.typ new file mode 100644 index 0000000..70b9e64 --- /dev/null +++ b/lib/assert_aeq.typ @@ -0,0 +1,3 @@ +#let assert-aeq(left, right, precision: calc.pow(10, -6)) = { + assert(calc.abs(left - right) < precision) +} -- cgit