View Issue Details

IDProjectCategoryView StatusLast Update
0015308FPCRTLpublic2011-05-01 22:16
ReporterAndreas Assigned ToJonas Maebe  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Platformi386OSWindows 
Product Version2.2.4 
Target Version2.4.2Fixed in Version2.4.2 
Summary0015308: FormatFloat() returns wrong results
DescriptionIn some cases (at least two) formatfloat returns wrong results,
For input of 1.05e2 and 1.06e2 it returns '..050E+002' and '..060E+002', respectively. In all other cases I tried, the results were ok.
Steps To ReproduceTry the following simple test program for the cases 1.05e2 and 1.06e2:

program testformatfloat;

uses sysutils;

const
   val_format: string = '0.0000E+000';
   
var
   input: extended;

begin
   decimalseparator:='.';
   write('Float: ');
   readln(input);
   writeln('Output of formatfloat: '+formatfloat(val_format,input));
end.
TagsNo tags attached.
Fixed in Revision15201
FPCOldBugId0
FPCTarget
Attached Files

Relationships

related to 0013076 resolvedJonas Maebe FormatFloat returns wrong value 
related to 0014870 closedJonas Maebe Currency comparation/division not given the expected result 

Activities

Andreas

2009-12-10 10:02

reporter   ~0032891

Use the following testprogram:

program testformatfloat;
uses sysutils;
const
   val_format: string = '0.0000E+000';
var
   input: extended;
begin
   decimalseparator:='.';
   write('Float: ');
   readln(input);
   writeln('Output of formatfloat: '+formatfloat(val_format,input));
end.

Darek Mazur

2009-12-30 15:14

reporter   ~0033396

problem is with str
  str(1.0:10,s); writeln(s);
  str(1.05:10,s);writeln(s);
  str(1.05e2,s);writeln(s);
give results (:

 1.000E+00
 1.0E+0000
  1.050000000000000E+0002
^^// see moving

stocki

2009-12-30 16:08

reporter   ~0033399

Delphi 2010:

 1.0E+0000
 1.1E+0000
 1.05000000000000E+0002

Darek Mazur

2009-12-30 22:40

reporter   ~0033404

What about this patch

Index: real2str.inc
===================================================================
--- real2str.inc (wersja 14500)
+++ real2str.inc (kopia robocza)
@@ -381,12 +381,6 @@
               d := frac(d);
               if (f < 0) then
                 begin
- dec(currprec);
- if (currprec=0) then
- begin
- inc(spos);
- temp[spos]:='0';
- end;
                 end;
             end;
           { calculate the necessary fractional digits }

Jonas Maebe

2010-01-07 16:26

manager   ~0033495

Thanks for the patch.

Issue History

Date Modified Username Field Change
2009-12-10 10:00 Andreas New Issue
2009-12-10 10:02 Andreas Note Added: 0032891
2009-12-10 13:11 Jonas Maebe Relationship added related to 0013076
2009-12-10 13:11 Jonas Maebe FPCOldBugId => 0
2009-12-10 13:11 Jonas Maebe Severity block => major
2009-12-30 15:14 Darek Mazur Note Added: 0033396
2009-12-30 16:08 stocki Note Added: 0033399
2009-12-30 22:40 Darek Mazur Note Added: 0033404
2010-01-07 15:30 Jonas Maebe Status new => assigned
2010-01-07 15:30 Jonas Maebe Assigned To => Jonas Maebe
2010-01-07 16:26 Jonas Maebe Fixed in Revision => 14563
2010-01-07 16:26 Jonas Maebe Status assigned => resolved
2010-01-07 16:26 Jonas Maebe Fixed in Version => 2.5.1
2010-01-07 16:26 Jonas Maebe Resolution open => fixed
2010-01-07 16:26 Jonas Maebe Note Added: 0033495
2010-01-07 16:32 Jonas Maebe Relationship added related to 0014870
2010-05-02 15:35 Jonas Maebe Fixed in Revision 14563 => 15201
2010-05-02 15:35 Jonas Maebe Fixed in Version 2.5.1 => 2.4.1
2010-11-16 16:52 Jonas Maebe Target Version => 2.4.2
2011-05-01 22:16 Marco van de Voort Status resolved => closed