Res1 = 2.1234570000000002E+000
Res2 = 2.1234569549560547E+000
Res3 = 2.1234570000000002E+000
Res4 = 2.1234570000000002E+000
Res1 = 2.1234569549560547E+000
Res2 = 2.1234569549560547E+000
Res3 = 2.1234570000000001E+000
Res4 = 2.1234570000000001E+000
I found an inconsistency in results when dividing a float number by an integer in exponential notation and literal notation.For the 1E6 constant, the compiler uses the Single value type. And calculations of the corresponding accuracy. When an integer is used (1000000), the constant is converted to the Double type, and double-precision calculations are applied accordingly.
@ASerge How you explain this -Same. Change 1E6 to Double(1E6).
For the 1E6 constant, the compiler uses the Single value type. And calculations of the corresponding accuracy. When an integer is used (1000000), the constant is converted to the Double type, and double-precision calculations are applied accordingly.
@ASerge How you explain this -
program NumberTest; {$IFDEF FPC} {$MODE Delphi} {$ENDIF} var NumVar: Double; Res1: Double; begin NumVar := 2.123456789; Res1 := Round(NumVar * 1.0) / 1E6; WriteLn(PUInt64(@Res1)^); Res1 := Round(NumVar * 1.0); Res1 := Res1 / 1E6; WriteLn(PUInt64(@Res1)^); end.
FPC result -
$ ./consta.exe 4521832792723554304 4521832792735477133
The same here, Res1 is explicitly declared as Double.Constant (literal)! Not a variable, result, or anything else. The constant is defined as the Single type.
Constant (literal)! Not a variable, result, or anything else. The constant is defined as the Single type.In that case it is a bug. An untyped const should take the highest possible resolution for the platform.
In that case it is a bug. An untyped const should take the highest possible resolution for the platform.Is this documented somewhere?
See https://wiki.freepascal.org/User_Changes_2.2.0#Floating_point_constants for more information. Back then, the current behaviour was considered Delphi-compatible (but perhaps an error was made). It also mentions a way to specify a higher minimal precision for floating point constants.So that should be reverted.
At least "default to Double" will be the improvement. IMO