mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-23 01:29:27 +02:00
* fixed FloatToDecimal() for inf/nan (mantis #14143, thanks to
Sergei Gorelkin for the test program) git-svn-id: trunk@13394 -
This commit is contained in:
parent
297bddba4a
commit
55578e8226
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -9191,6 +9191,7 @@ tests/webtbs/tw1409.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1412.pp svneol=native#text/plain
|
||||
tests/webtbs/tw14134.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1414.pp svneol=native#text/plain
|
||||
tests/webtbs/tw14143.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1416.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1430.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1433.pp svneol=native#text/plain
|
||||
|
@ -2306,6 +2306,7 @@ End;
|
||||
Procedure FloatToDecimal(Out Result: TFloatRec; const Value; ValueType: TFloatValue; Precision, Decimals : integer);
|
||||
var
|
||||
Buffer: String[254]; //Though str func returns only 25 chars, this might change in the future
|
||||
InfNan: string[3];
|
||||
Error, N, L, Start, C: Integer;
|
||||
GotNonZeroBeforeDot, BeforeDot : boolean;
|
||||
begin
|
||||
@ -2329,7 +2330,26 @@ begin
|
||||
Inc(N);
|
||||
Result.Negative := (Buffer[N] = '-');
|
||||
if Result.Negative then
|
||||
Inc(N);
|
||||
Inc(N)
|
||||
else if (Buffer[N] = '+') then
|
||||
inc(N);
|
||||
{ special cases for Inf and Nan }
|
||||
if (L>=N+2) then
|
||||
begin
|
||||
InfNan:=copy(Buffer,N,3);
|
||||
if (InfNan='Inf') then
|
||||
begin
|
||||
Result.Digits[0]:=#0;
|
||||
Result.Exponent:=32767;
|
||||
exit
|
||||
end;
|
||||
if (InfNan='Nan') then
|
||||
begin
|
||||
Result.Digits[0]:=#0;
|
||||
Result.Exponent:=-32768;
|
||||
exit
|
||||
end;
|
||||
end;
|
||||
Start := N; //Start of digits
|
||||
Result.Exponent := 0; BeforeDot := true;
|
||||
GotNonZeroBeforeDot := false;
|
||||
|
38
tests/webtbs/tw14143.pp
Normal file
38
tests/webtbs/tw14143.pp
Normal file
@ -0,0 +1,38 @@
|
||||
program t5;
|
||||
{$ifdef fpc}{$mode objfpc}{$h+}{$endif}
|
||||
|
||||
uses sysutils;
|
||||
|
||||
var
|
||||
frec: TFloatRec;
|
||||
code: Integer;
|
||||
|
||||
const
|
||||
posinf: Extended = 1.0/0.0;
|
||||
neginf: Extended = -1.0/0.0;
|
||||
nan: Extended = 0.0/0.0;
|
||||
|
||||
begin
|
||||
code := 0;
|
||||
FloatToDecimal(frec, posinf, fvExtended, 15, 15);
|
||||
if (frec.Exponent <> 32767) or frec.Negative or (frec.Digits[0] <> #0) then
|
||||
begin
|
||||
writeln('Positive infinity test failed');
|
||||
code := code or 1;
|
||||
end;
|
||||
|
||||
FloatToDecimal(frec, neginf, fvExtended, 15, 15);
|
||||
if (frec.Exponent <> 32767) or (not frec.Negative) or (frec.Digits[0] <> #0) then
|
||||
begin
|
||||
writeln('Negative infinity test failed');
|
||||
code := code or 2;
|
||||
end;
|
||||
|
||||
FloatToDecimal(frec, nan, fvExtended, 15, 15);
|
||||
if (frec.Exponent <> -32768) or (frec.Digits[0] <> #0) then
|
||||
begin
|
||||
writeln('NaN test failed');
|
||||
code := code or 4;
|
||||
end;
|
||||
Halt(Code);
|
||||
end.
|
Loading…
Reference in New Issue
Block a user