[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fwrite-fread anomaly
From: |
Benedict G Archer |
Subject: |
fwrite-fread anomaly |
Date: |
Mon, 30 Mar 1998 10:48:34 -0800 |
I'm stumped by what seems strange behavior of fwrite with certain values,
viz. (-7^-30). The log fragment below shows storing a short test
vector to a binary file and reading it back with no apparent problem.
octave:82>vout = [2*pi,-7^-30,27^11]'
vout =
6.2832e+00
-4.4367e-26
5.5591e+15
octave:83>fhdl = fopen('trio.dbl','w');
octave:84>fwrite(fhdl,vout,'double');
octave:85>fclose(fhdl);
octave:86>fhdl = fopen('trio.dbl','r');
octave:87>vin = fread(fhdl,3,'double')
vin =
6.2832e+00
-4.4367e-26
5.5591e+15
octave:88>fclose(fhdl)
ans = 0
However the file, trio.dbl, has a size of 25 bytes instead of the expected
24 and is not readable with IBM APL/2 which reads other similar files
lacking this value normally. Examining the file reveals that a carriage
return (hex 0D) is inserted before the -7^-30 value. This extra character
is reproducibly inserted before this value whether saved by itself or as an
element in any array tested. No problem occurs if saved as a 4 byte
float. My system is OS/2 version 4 with Klaus Gebhardt's 2.09-b04 binaries.
Is this my error, or a bug in Octave, EMX or ? Why doesn't Octave
have a problem reading the file? My thanks to John Eaton and all who
contribute to octave, and to Klaus Gebhardt for making current OS/2
binaries available.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- fwrite-fread anomaly,
Benedict G Archer <=