From 8a1de9cc709b2a9470541a229d2134f022a28301 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 28 Mar 2022 14:56:17 -0400 Subject: modernize msd() and ms2d() --- big.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'big.c') diff --git a/big.c b/big.c index b438b3b..02753f6 100644 --- a/big.c +++ b/big.c @@ -562,21 +562,26 @@ word len(word x) return n; } -word msd(x) /* most significant digit of big x */ -word x; +/* most significant digit of big x */ +word msd(word x) { - while (rest(x)) + while (rest(x)) { x = rest(x); - return (digit(x)); /* sign? */ + } + + return digit(x); /* sign? */ } -word ms2d(x) /* most significant 2 digits of big x (len>=2) */ -word x; +/* most significant 2 digits of big x (len>=2) */ +word ms2d(word x) { word d = digit(x); x = rest(x); - while (rest(x)) - d = digit(x), x = rest(x); + while (rest(x)) { + d = digit(x); + x = rest(x); + } + return (digit(x) * IBASE + d); } -- cgit v1.2.1