[fpc-pascal] Floating point question

James Richters james.richters at productionautomation.net
Sun Feb 4 17:55:55 CET 2024


What is the proper way to use $EXCESSPRECISION ?   I tried:
 
program TESTDBL1 ;
{$EXCESSPRECISION ON}
 
Const
    TT_Const = 8427 + 33 / 1440.0 ;
    SS_Const = 8427 + Double(33 / 1440.0) ;
 
Begin
   WRITELN ( 'TT_Const = 8427 + 33 / 1440.0 ;                           =' , TT_Const  : 20 : 20 ) ;
   WRITELN ( 'SS_Const = Double(8427 + 33 / 1440.0);                    =' , SS_Const  : 20 : 20 ) ;
end.
 
 
I get 
 
TT_Const = 8427 + 33 / 1440.0 ;                           =8427.02246100000000000000
SS_Const = Double(8427 + 33 / 1440.0);                    =8427.02291666716340000000
 
I expected them to be both the same. 
 
James
 
-----Original Message-----
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of James Richters via fpc-pascal
Sent: Sunday, February 4, 2024 10:52 AM
To: 'FPC-Pascal users discussions' <fpc-pascal at lists.freepascal.org>
Cc: James Richters <james.richters at productionautomation.net>
Subject: Re: [fpc-pascal] Floating point question
 
Hi Jonas,
That’s Interesting,  Thank you very much for the links!! Not only an explanation but a solution. 
The original is how I would expect it to work,  If it's for Delphi compatibility why not only do that when in Mode Delphi?   If not in mode Delphi who cares if it's compatible?
Delphi is completely wrong to do it this way.
I'm glad there is  $EXCESSPRECISION   I am Immediately putting that in every single program I have, because that is I always thought it would work, and I do have divisions where this can be a problem.
 
James
-----Original Message-----
From: fpc-pascal < <mailto:fpc-pascal-bounces at lists.freepascal.org> fpc-pascal-bounces at lists.freepascal.org> On Behalf Of Jonas Maebe via fpc-pascal
Sent: Sunday, February 4, 2024 7:21 AM
To:  <mailto:fpc-pascal at lists.freepascal.org> fpc-pascal at lists.freepascal.org
Cc: Jonas Maebe < <mailto:jonas at freepascal.org> jonas at freepascal.org>
Subject: Re: [fpc-pascal] Floating point question
 
On 03/02/2024 18:42, James Richters via fpc-pascal wrote:
> Constants are also evaluated wrong,you don’t know what that constant 
> is going to be used for, so all steps of evaluating a constant MUST be 
> done in extended by the compiler, or the answer is just wrong.
 
See
 <https://wiki.freepascal.org/User_Changes_2.2.0#Floating_point_constants> https://wiki.freepascal.org/User_Changes_2.2.0#Floating_point_constants
and  <https://www.freepascal.org/daily/doc/prog/progsu19.html> https://www.freepascal.org/daily/doc/prog/progsu19.html
fpc-pascal maillist  -   <mailto:fpc-pascal at lists.freepascal.org> fpc-pascal at lists.freepascal.org  <https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20240204/9a84da2b/attachment-0001.htm>


More information about the fpc-pascal mailing list