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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

158 van Wijngaarden, et el.fi;ref pos cpos = ClJOS off, lpos = lpos of book off;pos ccpos = cpos;if (cpos : = (p, l, c)) beyond lposthen cpos : = lpos;(- (logical file mended off) (f) I undefined);set mood (f, reading)elif pos bounds = book bounds (f);p < 1 v p > p of bounds + 1v l< 1 v l> lofbounds + 1v c < 1 v c> cofbounds+lthen cpos := ccpos; undefinedfij) proc reset = (ref file f) void :if - opened off v , reset possible (f) then undefinedelseref bool (read mood off) : = - put possible (f);ref bool (write mood off) : = - get possible (f);ref bool (char mood off) : = - bin possible (f);ref bool (bin mood off) : = false;ref pos (cpos off) := (I, 1, 1)fl;k) proc set char number = (ref file f, int c) void :if - opened off then undefinedelse ref ref pos cpos = cpos of f;while c of cpos ~ cdoif c < 1 v c > c of book bounds (f) + 1then undefinedelif c > c of cposthen space (f)else backspace (f)fiodfi;10.3.2. Transput values10.3.2.1. Conversion routines{The routines whole, fixed and float are intended to be used with theformatless output routines put, print and write when it is required to havea little extra control over the layout produced. Each of these routines hasa width parameter whose absolute value specifies the length of the stringto be produced by conversion of the arithmetic value Y provided. Each offixed and float has an after narameter to specify the number of digitsrequired after the decimal point, and an exp parameter in float specifiesthe width allowed for the exponent. If V cannot be expressed as a stringALGOL <strong>68</strong> Revised Report 159within the given width, even when the value of after, if provided, has beenreduced, then a string filled with errorchar (10.2.l.t) is returned instead.Leading zeroes are replaced by spaces and a sign is normally included.The user can, however, specify that a sign is to be included only fornegative values by specifying a negative width. If the width specified iszero, then the shortest possible string into which Y can be converted,consistently with the other parameters, is returned. The followingexamples illustrate some of the possibilities:print (whole (i, -4))which might print "...0", "..99", ".-99", "9999" or, if i weregreater than 9999, '....... , where ..... is the yield of errorchar:print (whole (i, 4))which would print ".+99" rather than "..99":print (whole (i, 0))which might print "0", "99", "-99", "9999" or "99999":print (fixed (x, -6, 3))which might print ".2.718", "27.183" or "271.83" (in which oneplace after the decimal point has been sacrificed in order to fitthe number in);print (fixed (x, O, 3))which might print "2.718", "27.183" or "271.828";print (float (x, 9, 3, 2))which might print "-2.7181o+0", "+2.7181o-1", or "+2.72~o+11" (inwhich one place after the decimal point has been sacrificed inorder to make room for the unexpectedly large exponent).}a) mode g number = union (~ L real~, ~ L int~) ;b) proc whole = (number v, int width) string :case v in{ (L int x):(int length : = abs width - (x < L 0 v width > 0 } ] I 0),Lint n : = abs x;if width = 0 thenLint m : = n; length : = O;whilem +:= L lO; length+:= I; m~ LOdo skip odfi;string s : = subwhole (n; length);if length = 0 v char in string (errorchar, Ioc int, s)then abs width x errorcharelse(x < L 01 ..... I: width > 01 "+"1 "") plusto s;(width ~ O I (abs width - upb s) x ,£,~lplusto s);Sfi)~,~ (L real x): fixed(x, width, 0) 7esac ;

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

Saved successfully!

Ooh no, something went wrong!