diff options
author | Jakob Kaivo <jkk@ung.org> | 2022-03-28 14:56:17 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2022-03-28 14:56:17 -0400 |
commit | 8a1de9cc709b2a9470541a229d2134f022a28301 (patch) | |
tree | b681d46ba5587d3d0e9495c75eeb499ddfd54dcc /big.c | |
parent | ae94463be87baa4e826cd1e18a8ec94abc0a5a45 (diff) |
modernize msd() and ms2d()
Diffstat (limited to 'big.c')
-rw-r--r-- | big.c | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -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); } |