Paste: Roman numerals

Author: n
Mode: postscript
Date: Wed, 20 Jun 2012 11:54:50
Plain Text |
% Good for 1-3999.
/divmod  { 2 copy idiv 3 1 roll mod } bind def
/romnumz [ [ 1000 (m) ] [ 900 (cm) ] [ 500 (d) ] [ 400 (cd) ] [ 100 (c) ] [ 90 (xc) ] [ 50 (l) ] [ 40 (xl) ] [ 10 (x) ] [ 9 (ix) ] [ 5 (v) ] [ 4 (iv) ] [ 1 (i) ] ] def
/cvroman {  % 42 cvroman (xlii)
  () exch   % () n
  romnumz { aload pop     % () n 1000 (m)
    3 1 roll divmod       % () (m) div rem
    3 1 roll dup 0 gt     % () rem (m) div bool
    { mark 3 1 roll       % () rem mark (m) div
      { dup } repeat pop  % () rem mark (m) (m) ... (m)
      counttomark 1 sub
      { conc } repeat
      exch pop            % () rem (mm...m)
      exch 3 1 roll       % rem () (mm...m)
      conc exch           % (mm...m) rem
    } { pop pop }         % () rem (m) div -> () rem
    ifelse
  } forall pop
} bind def

New Annotation

Summary:
Author:
Mode:
Body: