View Issue Details

IDProjectCategoryView StatusLast Update
0037935FPCCompilerpublic2020-10-16 23:07
ReporterBenito van der Zander Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionno change required 
Platformamd64OSlinux 
Product Version3.3.1 
Summary0037935: low precision floating point constants
DescriptionSome floating point constants are treated as single when they used to have more precision
Steps To Reproducebegin
  writeln(double(StrToFloat('1')) / double(StrToFloat('3.0')));
  writeln(double(1 / double(3.0)));
  writeln((1 / double(3.0)));
  writeln(double(1 / 3));
  writeln(double(1 / 3.0));
  writeln(double(1 / 3.0):22:22);
  writeln((1 / 3.0));
  writeln((1 / single(3.0)));

end.

In 3.0.4 it prints very pretty:

 3.3333333333333331E-001
 3.3333333333333333E-001
 3.3333333333333333E-001
 3.3333333333333333E-001
 3.3333333333333333E-001
0.3333333333333333300000
 3.333333333E-01
 3.333333333E-01


in trunk r47006 it prints:

 3.3333333333333331E-001
 3.3333333333333331E-001
 3.3333333333333331E-001
 3.3333333333333331E-001
 3.3333334326744080E-001
0.3333333432674408000000
 3.333333433E-01
 3.333333433E-01

Guess the last two are valid ways to print a single 1/3, but why is double(1 / 3.0) calculated with single precision?
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Florian

2020-10-16 23:07

administrator   ~0126355

> double(1 / 3.0) calculated with single precision?

Because only the operand types determine the result type in pascal: 1 fits in single; 3.0 fits in single => single division.

Issue History

Date Modified Username Field Change
2020-10-16 22:50 Benito van der Zander New Issue
2020-10-16 23:07 Florian Assigned To => Florian
2020-10-16 23:07 Florian Status new => resolved
2020-10-16 23:07 Florian Resolution open => no change required
2020-10-16 23:07 Florian FPCTarget => -
2020-10-16 23:07 Florian Note Added: 0126355