[fpc-pascal] Floating point question

Thomas Kurz fpc.2021 at t-net.ruhr
Tue Feb 6 12:59:22 CET 2024


I'd like to apologize, because my intention hasn't been to raise controverse discussions. I'm very thankful about the explanation. From the beginning, I knew that the error was on my side, but I didn't know *what* I'm doing wrong.

Again, thanks for helping.

Kind regards,
Thomas



----- Original Message ----- 
From: James Richters via fpc-pascal <fpc-pascal at lists.freepascal.org>
To: 'FPC-Pascal users discussions' <fpc-pascal at lists.freepascal.org>
Sent: Sunday, February 4, 2024, 18:25:39
Subject: [fpc-pascal] Floating point question

I agree with Aadrian 100%
 
"New behaviour: floating point constants are now considered to be of the lowest precision which doesn't cause data loss"

We are getting data loss!!!! So it's doing it WRONG.

So we are all living with a stupid way of doing things so some Delphi code won't have warnings?

Who came up with this???????????????

The old way was CORRECT,   instead of changing it for everyone making it wrong for most users, a compiler directive should have been needed to get rid of the warnings, or ONLY applied in Mode Delphi.  Not to make everything incorrect for everyone unless you add a directive.     The problem with this that no one is expecting to need to add a directive to do things right. 

Consider this:
 
Var
  MyVariable : Extended;

MyVariable := 8427 + 33 / 1440.0;

Since I am storing the result in an Extended, I DO NOT EXPECT the 33/1440 to be a SINGLE, that is NUTS!!
I expect it to be all done in Extended. Why would anyone expect the contents of MyVariable to be butchered by storing the 33/1440 in single precision.

In other words
I expect the result of these both to be the same:

program TESTDBL1 ;

Var
    AA : Extended;
    BB : Extended;
    CC : Extended;
    DD : Extended;
    EE : Extended;

begin
   AA := 8427;
   BB := 33;
   CC := 1440.0;
   DD := AA+BB/CC;
   EE := 8427+33/1440.0;
   WRITELN ( 'DD =' , DD : 20 : 20 ) ;
   WRITELN ( 'EE =' , EE : 20 : 20 ) ;
end.

But they are NOT
DD =8427.02291666666666625000
EE =8427.02246093750000000000

EE is WRONG and can never be considered right.   Why would ANY user with the code above expect that the 33/1440 would be done as a single, thus causing a loss of precision. 

Again:
"New behaviour: floating point constants are now considered to be of the lowest precision which doesn't cause data loss"

This was NOT done in the lowest precision which doesn't cause data loss.. we lost data!!!!   We are no longer Extended precision, anything at all we use EE for is WRONG.

This is CLEARLY WRONG!  The default should be the old way and if you don't like the Delphi warnings, you can make a switch to do it this new stupider and WRONG way.

I strongly feel this should be reverted, it's just wrong.   This makes no sense to me at all.   It's wrong to need to add a compiler directive to do things as they are expected by the vast majority to be, the directive should be needed for those few who even noticed the warnings in Delphi, and they were just warnings, not a substantial reduction in precision. 

James

>But not at the price of loss in precision ! Unless an explicit compiler switch like --fast-math is passed 


_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list