f.couperin wrote:
Frank Heckenbach wrote :
[...]
OK, we could do 103000 / 10**3 rather than 103000 * 10**(-3)... I'm changing this now (will be uploaded soon), and then this test works indeed...
Great. Thanks. I just downloaded the new version and it works fine. In order to understand a little more, may I ask you what did you exactly change in the sources ?
The following. However, doing the other things will be a bigger change, possibly affecting more or less the whole function (maybe it'll be better to rewrite it from scratch, but I'm not sure offhand).
--- file.c.orig Mon Apr 9 09:46:36 2001 +++ file.c Wed Apr 4 12:18:32 2001 @@ -2190,24 +2190,24 @@ ch = _p_direct_getc (File); }
- if (enegative) + if (val != 0.0) { - frac = 1.0; - for (i = 1; i <= expon; i++) - frac /= 10.0; - - if (frac == 0.0) - IOERROR (556, 0.0); - - val *= frac; - } - else - for (i = 1; i<= expon; i++) - { - lastval = val; - val = 10.0 * val; - if (!_p_realeq (val / 10.0, lastval)) - IOERROR (556, 0.0); + if (enegative) + { + /* @@ should do square and divide */ + for (i = 1; i <= expon; i++) + val /= 10.0; + if (val == 0.0) /* note that val != 0.0 originally */ + IOERROR (556, 0.0); /*@@ or should we just return 0? */ + } + else + { + /* @@ should do square and multiply */ + for (i = 1; i <= expon; i++) + val *= 10.0; + if (_p_isinf (val) || _p_isnan (val)) + IOERROR (556, 0.0); + } }
}
I'm wondering if there's a way to write a binary (or hexadecimal) representation of the LongReal type in a text file, a clear and understandable representation that could be read back by the program without any difference with the original number. I wrote LongReal numbers to a File Of LongReal, and I translated this file into an hexadecimal representation,
Yes, that's a way to do it. (You could achieve the same within the program, by type casting to an array of bytes or something -- if you need to have a text file. Normally, a file of LongReal would be most appropriate.)
I wanted to create a data file that I can read and change into a text editor. What I did to elude the problem : I created a program that can read and write something similar to the "Hex Float" representation I discovered in GCC. There is no more change between the numbers I wrote and the numbers I read into a file. (But the "Hex Float" representation is quite exotic to me...)
Before I read the last paragraph, I was just going to suggest this, but more as a joke. ;-) Hex (or binary) floats are certainly most appropriate for a computer, but very hard to read (or even change) for most humans...
To read back normal (decimal) floats, you probably need a new reading routine -- either as a replacement in the RTS (see above), or in your own program (i.e., a routine that reads the file char by char and assembles the number).
[...]
The details of the representation are available in many places, I suppose. They're printed in the BP manual AFAIR, and they're probably also available on the Net.
On my computer (Intel Pentium 120 + Windows 98), "LongReal" is the Intel IEEE Double-Extended wich is 10 bytes long (but stored in 12 bytes : I didn't understand the hidden reason why...).
Alignment. For most 32 bit processors (including IA32 in 32 bit mode) it's faster to move (multiples of) 32 bits, i.e. 4 bytes, than 16 bits.
Frank