On Wed, 27 Mar 2002, Martin Liddle wrote:
Forwarded as this doesn't seem to have been sent to the list.
Alle 20:55, martedì 26 marzo 2002, hai scritto:
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.
Here it is:
#include <stdio.h> #include <math.h>
int main()
{
int i; double ris, esp;
for(i=1;i<=100;i++) {
esp = (double)i * 1000.0; ris = exp(-esp); printf("Exp of %g = %g\n", esp, ris);
}
}
On various platforms I got the same results (0). But nevertheless, we know the results are near to zero but never can become zero. C++ treats numbers (double) between ± ~10**(-323.3) and 0.0 as zero. There is no binary representation of numbers within this gap. Try this modification of your C applet:
#include <stdio.h> #include <math.h> int main() { int i; double ris, esp; for(i=745130;i<=745136;i++) { esp = (double)i * 0.001; ris = exp(-esp); printf("Exp of %g = %g\n", esp, ris); } }
gives: Exp of 745.13 = 4.94066e-324 Exp of 745.131 = 4.94066e-324 Exp of 745.132 = 4.94066e-324 Exp of 745.133 = 4.94066e-324 Exp of 745.134 = 0 <-- finito de la musica Exp of 745.135 = 0 Exp of 745.136 = 0
Your application has 3 choices if esp becomes > ~745.133: 1. assume the result is 0.0 (C++, dangerous) 2. assume the result is ~10**(-323.3) (also dangerous) 3. mistrust your input values, abort the program (GPC)
I found some useful info about IEEE 754 (valid values, NaNs etc.) at: http://www.research.microsoft.com/~hollasch/cgindex/ coding/ieeefloat.html
Ernst-Ludwig