Anonymous user
Negative base numbers: Difference between revisions
m
→handles up to -10): changed some comments and whitespace.
m (→version 2 (up to base -71): changed wording in the REXX section header.) |
m (→handles up to -10): changed some comments and whitespace.) |
||
Line 1,552:
Both REXX versions use a type of ''assert'' (a function call of '''OK''') that converts the numbers in the
<br>negative base back to the original number in base ten (and issues an error message if not correct).
===
<lang rexx>/*REXX pgm converts & displays a base ten integer to a negative base number (up to -10).*/
@=' converted to base '; numeric digits 300 /*be able to handle ginormous numbers. */
n= 10; b= -2;
n= 146; b= -3;
n= 15; b= -10;
n= -15; b= -10;
n= 0; b= -5;
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
nBase: procedure; parse arg x,r;
if r<-10 | r>-2 then do; say 'base' r "must be in range: -2 ───► -10"; exit 13; end
end
return word($ 0, 1) /*possibly adjust for a zero value. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
ok: ?=; if pBase(
/*──────────────────────────────────────────────────────────────────────────────────────*/
pBase: procedure; parse arg x,r;
if r<-10 | r>-2 then do; say 'base' r "must be in range: -2 ───► -10"; exit 13; end
p= p + 1
end /*j*/
return $</lang>
{{out|output|text= when using the default inputs:}}
|