From c7801f7c1e5e9ca1dee061f011492ba37e0e1c73 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 15 Feb 2024 13:53:41 +0100 Subject: Added number conversion utility functions --- std/Number/Conversion.bruijn | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 std/Number/Conversion.bruijn (limited to 'std/Number/Conversion.bruijn') diff --git a/std/Number/Conversion.bruijn b/std/Number/Conversion.bruijn new file mode 100644 index 0000000..ff08f89 --- /dev/null +++ b/std/Number/Conversion.bruijn @@ -0,0 +1,16 @@ +# convert bases to other bases + +:import std/Number/Unary U +:import std/Number/Ternary T + +# convert unary numbers to ternary +unary-to-ternary [0 T.inc (+0)] ⧗ Unary → Ternary + +:test (unary-to-ternary (+0u)) ((+0)) +:test (unary-to-ternary (+2u)) ((+2)) + +# convert ternary numbers to unary +ternary-to-unary [T.apply 0 U.inc (+0u)] ⧗ Ternary → Unary + +:test (ternary-to-unary (+0)) ((+0u)) +:test (ternary-to-unary (+2)) ((+2u)) -- cgit v1.2.3