10.07.2015 Views

Algol 68 - ACM Digital Library

Algol 68 - ACM Digital Library

Algol 68 - ACM Digital Library

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

160van Wijngaarden, et al./ALGOL <strong>68</strong> Revised Report161c)d)proc fixed = (number v, int width, after) string :case v in(L real x):if int length : = abs width - (x < L 0 v width > 01 11 0);after >_ 0 ^ (length > after v width = O)then L real y = abs x;if width = 0then length : = (after = 0 [ i I 0);while y + L.5 x L.l I after >_L lO I lengthdo length +:= 1 od;length +: = (after = 0 [ 0 [ after + 1)fl;string s := subfixed (y, length, after);if - char in string (errorchar, Ioc int, s)then (length > upb s a y < IL 1.0[ "O" plusto s);(x < L 01 ..... l: width > 01 "+"[ "") plusto s;(width ~ O I (abs width - upb s) x '£':lplusto s);8elif after > 0then fixed (v, width, after - 1)else abs width x errorcharflelse undefined; abs width x errorchartit",It (Lint x): fixed (L real (x), width, after) ~"esac ;proc float = (number v, int width, after, exp) string :case v in(L real x):if int before = abs width - abs exp - (after ~ 01 after + 1 I O) - 2;sign before + sign after > 0then string s, L real y : = abs x, int p : = O;L standardize (y, before, after, p);s:=fixed (sign x x y, sign width x (abs width - abs exp - 1),after) + "1o" + whole (p, exp);if exp = 0 V char in string (errorchar, Ioc int, s)thenfloat (x, width, (after ~ 01 after - 1 [ 0),(exp > 0 [ exp + 1 [ exp - 1))else sfielse undefined; abs width x errorchartit,(Lint x): float (L real (x), width, after, exp) #esac ;e)f)g)h)proc 9 subwhole = (number v, int width) string :¢ returns a string of maximum length 'width' containing adecimal representation of the positive integer 'v' ¢case v In~ (L int x):esac ;begin string s, L int n : = x;while dig char (8 (n mod JL 10)) plusto s;n s:= L lO; n~ LOdo skip od;(upb s > width I width x errorchar l s)endproc .~ subfixed = (number v, int width, after) string :¢ returns a string of maximum length 'width' containing arounded decimal representation of the positive real number'v'; if 'after' is greater than zero, this string contains adecimal point followed by 'after' digits ¢case v in(L real x):begin siring s, int before : = O;L real y : = x + L .5 x L .1 I after;proc choosedig = (ref L real y) char :dig char (tint c : = S entier (y x: = L 10.0); (c > 91 c : = 9);y -: = Kc; c));while y _> IL 10.0 I before do before +: = 1 od;y/: = L 10.0 I before;to before do s plusab choosedig (y) od;(after > 0 [ s plusab ".");to after do s plusab choosedig (y) od;(upb s > width [ width x errorchar J s)endesac ;proc 9 L standardize = (ref L real y, int before, after, ref int p) void :¢ adjusts the value of 'y' so that it may be transput accordingto the format $ n(before)d . n(after)d $; 'p' is set so t/zaty x 10 t p is equal to the original value of 'y'¢beginJL realg = L 10.0 I before; L real h = g × L .1;whiley >_g doyx:= L .1; p+:= 1 od;(y~ JLO.O I while y < h do yx:= L 10.0; p -:= 1 od);(y+L.5xL.1 l after>_gly:=h; p+:= l)end;proc 9 dig char = tint x) char : "0123456789abcdef" I x + i I :

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!