On Tue, 26 Mar 2002, Silvio a Beccara wrote:
Hello,
thank you for your help; under which version have you tried compiling this, and under which OS?
[pal06] bohnen $ gpc -v Reading specs from /afs/desy.de/user/b/bohnen/.gnu/lib/gcc-lib/i386-suse-linux/2.95.2/specs gpc version 20020304, based on 2.95.2 19991024 (release)
[pal06] bohnen $ uname -a Linux pal06 2.4.18 #1 SMP Tue Mar 5 15:27:45 MET 2002 i686 unknown
AFAIK any floating point unit can be configured to treat 'out of range' FP-numbers (NaNs) as legal infinity/zero values or as errors. I couldn't find any hint about 'NaN' or 'IEEE' in the gpc - units directory to control this behavior. If there is no user control on that, the current behavior of gpc seems to me the best solution. Otherwise one might run into severe mathematical problems without any notification.
Ernst-Ludwig
Regards
Silvio
Hello, I changed your program somewhat:
PROGRAM espa; var i, j, k : integer; esp, res : double;
begin writeln (exp(1.0));
^^^^^^^^^^^^^^^^^^^ this is garbage, I forgot the value of e
for i := 1 to 50000 do begin esp := i * 0.1 ; res := exp ( -esp ); writeln (' Minus the exponential of ', esp :5 :1, ' is ', res ); end end.
Last lines written are: ...... Minus the exponential of 744.9 is 4.940656458412465e-324 Minus the exponential of 745.0 is 4.940656458412465e-324 Minus the exponential of 745.1 is 4.940656458412465e-324 espa: error in exponentiation (Numerical result out of range) (error #700 at 8049c8a)
This indicates that res runs into undefined range between zero and minimum valid value of IEEE double precision numbers. Minimum decimal value is approximately +/- 10**(-323). If your application allows lower values to be interpreted as zero (0.0) you may tell it to gpc, but I don't know how to do that..
Ernst-Ludwig
On Tue, 26 Mar 2002, Silvio a Beccara wrote:
Hello,
I tried compiling this simple program, with GPC RC3 (20020304), with GCC 2.95.3 (20010315).
program espa;
var
i, j, k: integer;
esp: double;
res: double;
begin
for i := 1 to 50 do begin
esp := i * 1000 ;
res := exp ( -esp );
writeln (' Minus the exponential of ', esp :1 :0, ' is ', res :1 :15 );
end;
end.
Surprisingly, and disappointingly, when I run it I get the following result:
espa: error in exponentiation (Numerical result out of range) (error #700 at 8049c75)
while with any Pascal (like FPC), and C compiler, I get no error (like it should be ). It really looks like a bug.
Can anyone help?
Thanks, regards
Silvio a Beccara
Silvio a Beccara wrote:
[...]
Surprisingly, and disappointingly, when I run it I get the following result:
espa: error in exponentiation (Numerical result out of range) (error #700 at 8049c75)
while with any Pascal (like FPC), and C compiler, I get no error (like it should be ). It really looks like a bug.
I'd be surprised about C compilers since (as Maurice noted) GPC internally just calls the C function and checks errno. Did you actually check errno when trying it in C?
Ernst-Ludwig Bohnen wrote:
AFAIK any floating point unit can be configured to treat 'out of range' FP-numbers (NaNs) as legal infinity/zero values or as errors. I couldn't find any hint about 'NaN' or 'IEEE' in the gpc - units directory to control this behavior.
GPC currently doesn't do anything special about it and provides no access with built-in methods (yet).
If there is no user control on that, the current behavior of gpc seems to me the best solution. Otherwise one might run into severe mathematical problems without any notification.
Good point. So I'd tend to leave things as they are.
Frank
Hello,
Good point. So I'd tend to leave things as they are.
how do I run my program, then? I cannot have it stop every time it has to calculate the exponential of something smaller than -1000. This is simply not acceptable. For instance, with FPC I get everything correct. There are no errors - just plain math!
Before I forget: with the C program, I just compiled it very normally, and it gave me no error, just the correct results.
Thanks, regards
Silvio
In article 200203261732.SAA15974@science.unitn.it, Silvio a Beccara abeccara@science.unitn.it writes
Before I forget: with the C program, I just compiled it very normally, and it gave me no error, just the correct results.
Post a small test program in C showing what you did.
On Tue, 26 Mar 2002, Silvio a Beccara wrote:
Hello,
Good point. So I'd tend to leave things as they are.
how do I run my program, then? I cannot have it stop every time it has to calculate the exponential of something smaller than -1000. This is simply not acceptable. For instance, with FPC I get everything correct. There are no errors - just plain math!
Before I forget: with the C program, I just compiled it very normally, and it gave me no error, just the correct results.
Thanks, regards
Silvio
Dear Silvio, ..plain math with IEEE Standard 754 double precision means that we can NOT trust results of exp (x), where x < ~-745.1 . Any result is simply undefined in IEEE. 'User friendly' systems (returning 0.0) may lead you up the garden path. Your application needs to know how to handle these special cases in order to get correct results. Further operations like '*' and '/' will give misleading results, even though legal in plain math!
Regards, Ernst-Ludwig