------- Comment #10 from burnus at gcc dot gnu dot org 2009-10-01 07:35 ------- (In reply to comment #9) > Rounding modes are now implemented for formatted WRITE operations. I do not > have a clear enough idea of what the rounding modes really mean for READ > operations. For example: > > "Rounding is done for all I/O, including input. For example, if you have: > read ("0.1", *, rounding="up") x > read ("0.1", *, rounding="down") y > then you will have x == nearest(y, -1.)"
For REAL(8) I would expect for 0.1_8 with rounding up and down: 0.10000000000000001 9.99999999999999917E-002 or written as binary: 11111110111001100110011001100110011001100110011001100110011010 (= 0.1 rnd up) 11111110111001100110011001100110011001100110011001100110011001 (= 0.1 rnd down) > Is this really what is meant by rounding up or down? I think so. > The internal representation of .1 may already be rounded up or down > from a binary representation that carried more bits in the conversion > process. If we do not have access to more bits, how are we to know > whether it is not already "half way in between" Well, the rounding has to be based on the string (= decimal) number; if you already have a binary number, it is too late. > Similarly with nearest. Using "nearest" with "-1." in this example only works if you know that "read" automatically rounds up for 0.1. * * * Handling this efficiently and reliably is presumably nontrivial. See for instance: http://netlib.org/fp/ (esp. http://netlib.org/fp/gdtoa.tgz) http://dx.doi.org/10.1145/989393.989430 http://www.informatik.uni-trier.de/Reports/TR-08-2004/rnc6_10_hack.pdf and references therein. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35862