mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 20:49:09 +02:00
* fixed more bugs due to inexact nature of FPU
This commit is contained in:
parent
872031518d
commit
7e63fc9d28
@ -129,6 +129,11 @@ var
|
|||||||
dec(currPrec);
|
dec(currPrec);
|
||||||
inc(spos);
|
inc(spos);
|
||||||
temp[spos] := chr(intPart+ord('0'));
|
temp[spos] := chr(intPart+ord('0'));
|
||||||
|
if temp[spos] > '9' then
|
||||||
|
begin
|
||||||
|
temp[spos] := chr(ord(temp[spos])-10);
|
||||||
|
roundStr(temp,spos-1);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
corrVal := int(intPartStack[stackPtr]) * 10.0;
|
corrVal := int(intPartStack[stackPtr]) * 10.0;
|
||||||
dec(stackPtr);
|
dec(stackPtr);
|
||||||
@ -284,7 +289,7 @@ begin
|
|||||||
if (spos = 2) and (d <> 0.0) then
|
if (spos = 2) and (d <> 0.0) then
|
||||||
begin
|
begin
|
||||||
{ take rounding errors into account }
|
{ take rounding errors into account }
|
||||||
while d < 1.0-roundCorr do
|
while d < 0.1-roundCorr do
|
||||||
begin
|
begin
|
||||||
d := d * 10.0;
|
d := d * 10.0;
|
||||||
dec(correct);
|
dec(correct);
|
||||||
@ -294,9 +299,7 @@ begin
|
|||||||
if f >= 0 then
|
if f >= 0 then
|
||||||
dec(currPrec);
|
dec(currPrec);
|
||||||
end;
|
end;
|
||||||
{ we decreased currPrec once too much }
|
dec(correct);
|
||||||
if f >= 0 then
|
|
||||||
inc(currPrec);
|
|
||||||
end;
|
end;
|
||||||
{ current length of the output string in endPos }
|
{ current length of the output string in endPos }
|
||||||
endPos := spos;
|
endPos := spos;
|
||||||
@ -304,30 +307,32 @@ begin
|
|||||||
if (currPrec >= 0) then
|
if (currPrec >= 0) then
|
||||||
begin
|
begin
|
||||||
if (currPrec > 0) then
|
if (currPrec > 0) then
|
||||||
{ do some preliminary rounding (necessary, just like the }
|
{ round }
|
||||||
{ rounding afterwards) }
|
|
||||||
begin
|
begin
|
||||||
corrVal := 0.5;
|
corrVal := 0.5;
|
||||||
for fracCount := 1 to currPrec do
|
for fracCount := 1 to currPrec do
|
||||||
corrVal := corrVal / 10.0;
|
corrVal := corrVal / 10.0;
|
||||||
if d > corrVal then
|
if d > corrVal then
|
||||||
d := d + corrVal;
|
d := d + corrVal;
|
||||||
|
if int(d) = 1 then
|
||||||
|
begin
|
||||||
|
roundStr(temp,spos);
|
||||||
|
d := frac(d);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
{ 0.0 < d < 1.0 if we didn't round of earlier, otherwise 1 < d < 10 }
|
|
||||||
if d < 1.0-roundCorr then
|
|
||||||
corrVal := frac(d) * 10
|
|
||||||
else corrVal := d;
|
|
||||||
{ calculate the necessary fractional digits }
|
{ calculate the necessary fractional digits }
|
||||||
for fracCount := 1 to currPrec do
|
for fracCount := 1 to currPrec do
|
||||||
begin
|
begin
|
||||||
|
d := frac(d) * 10.0;
|
||||||
inc(spos);
|
inc(spos);
|
||||||
temp[spos] := chr(trunc(corrVal)+ord('0'));
|
temp[spos] := chr(trunc(d)+ord('0'));
|
||||||
corrVal := frac(corrVal)*10.0;
|
if temp[spos] > '9' then
|
||||||
|
{ possible because trunc and the "*10.0" aren't exact :( }
|
||||||
|
begin
|
||||||
|
temp[spos] := chr(ord(temp[spos]) - 10);
|
||||||
|
roundStr(temp,spos-1);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
{ round off. We left a zero at the start, so we can't underflow }
|
|
||||||
{ to the length byte }
|
|
||||||
if (corrVal-5.0 > roundCorr) then
|
|
||||||
roundStr(temp,spos);
|
|
||||||
{ new length of string }
|
{ new length of string }
|
||||||
endPos := spos;
|
endPos := spos;
|
||||||
end;
|
end;
|
||||||
@ -388,7 +393,10 @@ end;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.28 2000-03-17 20:20:33 jonas
|
Revision 1.29 2000-03-21 12:00:30 jonas
|
||||||
|
* fixed more bugs due to inexact nature of FPU
|
||||||
|
|
||||||
|
Revision 1.28 2000/03/17 20:20:33 jonas
|
||||||
* fixed rounding bugs with certain formatting parameters in str_real
|
* fixed rounding bugs with certain formatting parameters in str_real
|
||||||
* fixed tbs0218 so it compares both results only until max precision
|
* fixed tbs0218 so it compares both results only until max precision
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user