mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-02 19:43:15 +01:00
* Test for formatfloat negative zero
git-svn-id: trunk@15946 -
This commit is contained in:
parent
f7b268713d
commit
166ba412c9
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -9546,6 +9546,7 @@ tests/test/tstring9.pp svneol=native#text/plain
|
||||
tests/test/tstrreal1.pp svneol=native#text/plain
|
||||
tests/test/tstrreal2.pp svneol=native#text/plain
|
||||
tests/test/tstrreal3.pp svneol=native#text/plain
|
||||
tests/test/tstrreal4.pp svneol=native#text/plain
|
||||
tests/test/tsubdecl.pp svneol=native#text/plain
|
||||
tests/test/tsymlibrary1.pp svneol=native#text/pascal
|
||||
tests/test/ttpara1.pp svneol=native#text/plain
|
||||
|
||||
147
tests/test/tstrreal4.pp
Normal file
147
tests/test/tstrreal4.pp
Normal file
@ -0,0 +1,147 @@
|
||||
program tstrreal4;
|
||||
{ test for issue #13722 by Zeljan Rikalo}
|
||||
uses SysUtils;
|
||||
|
||||
procedure test;
|
||||
var
|
||||
s: string;
|
||||
r: double;
|
||||
begin
|
||||
{$IFDEF FPC}
|
||||
CurrencyFormat := 1;
|
||||
NegCurrFormat := 0;
|
||||
{$ENDIF}
|
||||
DecimalSeparator := '.';
|
||||
r := 0.001;
|
||||
s := FloatToStrF(r, ffGeneral, 12, 2);
|
||||
{must print 0.001 }
|
||||
writeln(s);
|
||||
if (s <> '0.001') then
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffFixed, 12, 2);
|
||||
{must print 0.00 }
|
||||
writeln(s);
|
||||
if (s <> '0.00') then
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffNumber, 12, 2);
|
||||
{must print 0.00 }
|
||||
writeln(s);
|
||||
if (s <> '0.00') then
|
||||
halt(1);
|
||||
|
||||
r := -0.00001;
|
||||
|
||||
s := FloatToStrF(r, ffGeneral, 12, 2);
|
||||
{must print -0.00001 }
|
||||
writeln(s);
|
||||
{$IFDEF FPC}
|
||||
if (s <> '-0.00001') then
|
||||
{$ELSE}
|
||||
if (s <> '-1E-05') then // is this DCC bug ?
|
||||
{$ENDIF}
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffExponent, 12, 2);
|
||||
{must print -1.00000000000E-05 }
|
||||
writeln(s);
|
||||
if (s <> '-1.00000000000E-05') then
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffFixed, 12, 2);
|
||||
{must print 0.00 }
|
||||
writeln(s);
|
||||
if (s <> '0.00') then
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffNumber, 12, 2);
|
||||
{must print 0.00 }
|
||||
writeln(s);
|
||||
if (s <> '0.00') then
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffCurrency, 12, 2);
|
||||
{must print without leading zero }
|
||||
writeln(s);
|
||||
if (length(s) > 0) and (Pos('-', s) > 0) then
|
||||
halt(1);
|
||||
|
||||
r := -0.00000;
|
||||
|
||||
s := FloatToStrF(r, ffGeneral, 12, 2);
|
||||
{must print 0 }
|
||||
writeln(s);
|
||||
if (s <> '0') then
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffExponent, 12, 2);
|
||||
{must print 0.00 }
|
||||
writeln(s);
|
||||
if (s <> '0.00000000000E+00') then
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffFixed, 12, 2);
|
||||
{must print 0.00 }
|
||||
writeln(s);
|
||||
if (s <> '0.00') then
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffNumber, 12, 2);
|
||||
{must print 0.00 }
|
||||
writeln(s);
|
||||
if (s <> '0.00') then
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffCurrency, 12, 2);
|
||||
{must print without leading zero }
|
||||
writeln(s);
|
||||
if (length(s) > 0) and (Pos('-', s) > 0) then
|
||||
halt(1);
|
||||
|
||||
// Now check if we remove leading negative sign by mistake
|
||||
r := -0.00001;
|
||||
|
||||
s := FloatToStrF(r, ffGeneral, 12, 5);
|
||||
{must print -0.00001 }
|
||||
writeln(s);
|
||||
{$IFDEF FPC}
|
||||
if (s <> '-0.00001') then
|
||||
{$ELSE}
|
||||
if (s <> '-1E-5') then // is this DCC bug ?
|
||||
{$ENDIF}
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffExponent, 12, 5);
|
||||
{must print -0.00001 }
|
||||
writeln(s);
|
||||
{$IFDEF FPC}
|
||||
if (s <> '-1.00000000000E-0005') then
|
||||
{$ELSE}
|
||||
if (s <> '-1.00000000000E-5') then
|
||||
{$ENDIF}
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffFixed, 12, 5);
|
||||
{must print 0.00 }
|
||||
writeln(s);
|
||||
if (s <> '-0.00001') then
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffNumber, 12, 5);
|
||||
{must print 0.00 }
|
||||
writeln(s);
|
||||
if (s <> '-0.00001') then
|
||||
halt(1);
|
||||
|
||||
s := FloatToStrF(r, ffCurrency, 12, 5);
|
||||
{must print without leading zero }
|
||||
writeln(s);
|
||||
if (length(s) > 0) and (Pos('-', s) = 0) then
|
||||
halt(1);
|
||||
writeln('Tests for FloatToStrF(): SUCCESS');
|
||||
end;
|
||||
|
||||
begin
|
||||
test;
|
||||
end.
|
||||
Loading…
Reference in New Issue
Block a user