
Hello All
A simple program to demonstrate my problem
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,
{ you can add units after this }
sysutils;
{$R *.res}
var
f : tmemorystream;
w : twriter;
r : treader;
d1,d2 : tdatetime;
c1,c2 : currency;
e1,e2 : extended;
s1,s2 : single;
begin
f:=tmemorystream.Create; // Does not matter which kind of stream
w:=twriter.Create(f,255);
d1:=encodedate(2010,1,1);
w.WriteDate(d1);
c1:=123.45;
w.WriteCurrency(c1);
e1:=12345.678;
w.WriteFloat(e1);
s1:=456.78;
w.WriteSingle(s1);
w.Free;
f.Seek(0,soFromBeginning);
r:=treader.Create(f,255);
d2:=r.ReadDate;
c2:=r.ReadCurrency;
e2:=r.ReadFloat;
s2:=r.ReadSingle;
r.Free;
f.Free;
writeln;
writeln('Expected:');
writeln(datetostr(d1));
writeln(c1,' ',currtostrf(c1,fffixed,2));
writeln(e1,' ',floattostrf(e1,fffixed,9,3));
writeln(s1,' ',floattostrf(s1,fffixed,9,2));
writeln;
writeln('Result:');
writeln(datetostr(d2));
writeln(c2,' ',currtostrf(c2,fffixed,2));
writeln(e2,' ',floattostrf(e2,fffixed,9,3));
writeln(s2,' ',floattostrf(s2,fffixed,9,2));
writeln;
end.
Running this program gives the following output:
Expected:
1-1-10
1.234500000000000000E+02 123.45
1.2345678000000000E+0004 12345.678
4.567799988E+02 456.78
Result:
30-12-99
1.234500000000000000E+06 1234500.00
1.2345678000000000E+0004 12345.678
1.139041280E+09 1139041280.00
Only the combination of twriter.writefloat and treader.readfloat is producing the expected correct result
The other combinations dont procduce right results.
Ok, I can use writefloat/readfloat on the other types too, because they are also floating point types, but why should I do so when there are procedures available?
Anybody else remarked these incorrect behaviour or is it special to my computer
