ROMAN$ ====== Convert a number to Roman numerals Usage: ====== romnum$ = ROMAN$(arabic%) where romnum$ is a string representing the number in Roman numerals. and arabic% is an integer between 1 and 3999 Limitations: ============ Romans didnt use zero, so ROMAN$(0) returns an empty string. In later times sometimes N (nulla) was used to represent zero. Values above 3999 use lines above the standard numerals to indicate multiples of thousands. They cant be represented here without the use of a special character set, so ROMAN$ is limited to values between (0) 1 and 3999. Negative numbers and numbers above 3999 return an Out of Range error. About: ====== This routine was written long ago as part of a general purpose date handling toolkit. Most of the useful bits from that toolkit have either been extracted or replaced by better things - except for this, so I thought I might as well.. There was no good reason to write this in assembler except for keeping all the relevant stuff together in a single package - and for fun and practise, of course. Basically it is just an implementation of: 100 DEFine FuNction RomanNum$(n) 110 LOCal ll, n%, m, r$(15) 120 IF n < 0 OR n% >= 4000: RETurn 'nonsense' 130 IF n = 0: RETurn 'N' 140 r$ = '': n% = n 150 FOR m = 1000,900,500,400,100,90,50,40,10,9,5,4,1 160 REPeat ll 170 n% = n% - m: IF n% < 0: n% = n% + m: EXIT ll 180 r$ = r$ & Rn$ 190 END REPeat ll 200 END FOR m 210 RETurn r$ 220 END DEFine RomanNum$ 230 : 240 DEFine FuNction Rn$ 250 SELect ON m 260 = 1: RETurn 'I' 270 = 4: RETurn 'IV' 280 = 5: RETurn 'V' 290 = 9: RETurn 'IX' 300 = 10: RETurn 'X' 310 = 40: RETurn 'XL' 320 = 50: RETurn 'L' 330 = 90: RETurn 'XC' 340 = 100: RETurn 'C' 350 = 400: RETurn 'CD' 360 = 500: RETurn 'D' 370 = 900: RETurn 'CM' 380 = 1000: RETurn 'M' 390 END SELect 400 END DEFine Rn$ 410 : Software status: ================ V0.01, pjw, 1992 Dec 19 V0.02, pjw, 2023 Sep 03, extracted, tweaked, re-tested and repackaged Conditions of use and DISCLAIMER as per Knoware.no
Generated by QuickHTM, 2023 Sep 05