From 78cb6a5dd59a0106298ab1d88767ef97ae254f45 Mon Sep 17 00:00:00 2001 From: d_m Date: Thu, 9 Nov 2023 22:08:42 -0500 Subject: [PATCH] comparisons for bc15 numbers --- src/bcb.c | 14 ++++++++++++++ src/bcb.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/bcb.c b/src/bcb.c index ee84398..fdb8ecd 100644 --- a/src/bcb.c +++ b/src/bcb.c @@ -226,6 +226,20 @@ bc15carry(int next, int *digit, int *carry) } } +bc3 +bc15cmp(bc15 a, bc15 b) +{ + int i; + for(i = 28; i >= 0; i -= 2) { + /* altered repr: 0 (-) 1 (zero) 2 (+) */ + bc3 x = ((a >> i) + 1) & 0x3; + bc3 y = ((b >> i) + 1) & 0x3; + if (x != y) + return x < y ? 3 : 1; + } + return 0; +} + // Unsigned(TODO: migrate to 11-00-01 encoding) int diff --git a/src/bcb.h b/src/bcb.h index fea1b32..46c4555 100644 --- a/src/bcb.h +++ b/src/bcb.h @@ -53,6 +53,7 @@ bc15 bc15tnor(bc15 a); bc15 bc15negate(bc15 a); bc15 bc15add(bc15 a, bc15 b); void bc15carry(int sum, int *digit, int *carry); +bc15 bc15cmp(bc15 a, bc15 b); // Unsigned int uc15int(uc15 t); -- 2.45.2