rang@cpsin3.cps.msu.edu (Anton Rang) (04/27/89)
I noticed that the rounding on small numbers done by writeln on VAX Pascal has a counter-intuitive (to me) result: writeln(-0.000001:6:4); ==> "0.0000" Somehow, it seems to me that "-0.0000" would make more sense (and it would make my report columns line up better :-). Rounding it to zero is correct, but I don't like losing the sign in the process.... Thoughts? +---------------------------+------------------------+---------------------+ | Anton Rang (grad student) | "VMS Forever!" | rec.music.newage is | | Michigan State University | rang@cpswh.cps.msu.edu | under discussion... | +---------------------------+------------------------+---------------------+
mithomas@bsu-cs.bsu.edu (Michael Thomas Niehaus) (04/27/89)
In article <2744@cps3xx.UUCP>, rang@cpsin3.cps.msu.edu (Anton Rang) writes: > I noticed that the rounding on small numbers done by writeln on VAX > Pascal has a counter-intuitive (to me) result: > > writeln(-0.000001:6:4); > > ==> "0.0000" It's been a while since I have tried anything like this, but it seems to me that Pascal cannot display the sign since the field is not wide enough. What you happen if you would try to display the same thing using a field that was 7 characters wide, still with 4 decimal places? I'd try it myself but I am using our UNIX system right now and soon I need to log onto our IBM 3083 to work on a COBOL project (bleh). -Michael -- Michael Niehaus UUCP: <backbones>!{iuvax,pur-ee}!bsu-cs!mithomas Apple Student Rep ARPA: mithomas@bsu-cs.bsu.edu Ball State University AppleLink: ST0374 (from UUCP: st0374@applelink.apple.com)
neubauer@bsu-cs.bsu.edu (Paul Neubauer) (04/27/89)
In article <6953@bsu-cs.bsu.edu> mithomas@bsu-cs.bsu.edu (Michael Thomas Niehaus) writes: >In article <2744@cps3xx.UUCP>, rang@cpsin3.cps.msu.edu (Anton Rang) writes: >> I noticed that the rounding on small numbers done by writeln on VAX >> Pascal has a counter-intuitive (to me) result: >> >> writeln(-0.000001:6:4); >> >> ==> "0.0000" > >It's been a while since I have tried anything like this, but it seems to >me that Pascal cannot display the sign since the field is not wide enough. >What you happen if you would try to display the same thing using a field >that was 7 characters wide, still with 4 decimal places? I'd try it myself Sorry, that is not what is going on here. The following short program shows that it always counts 0 as positive and always expands the field width to include everything to the left of the .: PROGRAM Signs (output); BEGIN writeln(-0.000001:6:4); writeln(-0.000001:7:4); writeln(-1.000001:6:4); writeln(-1.000001:7:4); END. {program Signs} The output from this program is: 0.0000 0.0000 -1.0000 -1.0000 That is, the total field width NEVER limits the width. The first width parameter to write[ln] is a LOWER bound to the width. The second width parameter is an UPPER bound. Anton will just have to be satisfied with the fact that zero is zero (at least for present purposes). Some numerical conventions do permit negative zero, but you can't get there from here. -- Paul Neubauer neubauer@bsu-cs.bsu.edu neubauer@bsu-cs.UUCP <backbones>!{iuvax,pur-ee}!bsu-cs!neubauer
csjr@admdev.cut.oz (Steve Rollinson) (05/01/89)
In article <6963@bsu-cs.bsu.edu>, neubauer@bsu-cs.bsu.edu (Paul Neubauer) writes: ...................................etc................... > Sorry, that is not what is going on here. The following short program shows > that it always counts 0 as positive and always expands the field width to > include everything to the left of the .: > > PROGRAM Signs (output); > > BEGIN > writeln(-0.000001:6:4); > writeln(-0.000001:7:4); > writeln(-1.000001:6:4); > writeln(-1.000001:7:4); > END. {program Signs} > > The output from this program is: > > 0.0000 > 0.0000 > -1.0000 > -1.0000 > ...............................etc........................... If you want your numbers to line up, you should use the same field widths throughout.... BEGIN writeln(-0.000001:7:4); writeln(-0.000001:7:4); writeln(-1.000001:7:4); writeln(-1.000001:7:4); END. {program Signs} I seem to recall that the decimal point counts as a character position in the integer part of the format, therefore -0.000001:6:4 would completely fill the field "0.0000" 123456 and -000001:7:4 would be represented by " 0.0000" 1234567 ... as essentially real numbers are displayed right justified. I believe that when the number "displayed" is <0 the output still allows the "-" to be displayed, thus allowing 1 more character in the output format. (Feel free to flame me if I'm wrong) ------------------------------------------------------------------------------- _ __ | _ _ | Steven Rollinson ( ` / ) / / | @ @ | Curtin University of Technology \ /--< _ / / . __ _ _ __ | > | Computing Centre \_) / |/(_)_/_/_<_/ /_\/(_)_/ /_ | ~ | Western Australia | | PSI%AUSTPAC.0505294523000::CSJR -------------------------------------------------------------------------------