C/pow: Różnice pomiędzy wersjami

Dodane 5336 bajtów ,  5 lat temu
m
m (Wycofano edycje użytkownika 80.53.70.123 (dyskusja). Autor przywróconej wersji to RedRad.)
c= sqrt(temp);
</source>
 
 
 
Inny przykład :
<source lang="c">
/*
gcc s.c -Wall -lm
*/
#include <math.h> /* isnormal */
#include <float.h>//DBL_MIN
#include <stdio.h>
 
int main ()
{
double x = 2.0;
int i=0;
 
while (1)
{
printf ("i = %3d ; x= %.16lf so ", i, x);
//
if (x<DBL_MIN) {printf ("x < DBL_MIN and "); break; }
else printf ("x > DBL_MIN and ");
//
if (isnormal(x)) printf ("x is normal and ");
else {printf ("x is subnormal \n "); break;}
//
if (x==1.0) {printf ("equal to 1.0\n"); break;}
else printf ("not equal to 1.0\n");
//
x=sqrt(x);
i+=1;
}
 
return 0;
}
 
</source>
 
Wynik:
 
<pre>
./a.out
i = 0 ; x= 2.0000000000000000 so x > DBL_MIN and x is normal and not equal to 1.0
i = 1 ; x= 1.4142135623730951 so x > DBL_MIN and x is normal and not equal to 1.0
i = 2 ; x= 1.1892071150027210 so x > DBL_MIN and x is normal and not equal to 1.0
i = 3 ; x= 1.0905077326652577 so x > DBL_MIN and x is normal and not equal to 1.0
i = 4 ; x= 1.0442737824274138 so x > DBL_MIN and x is normal and not equal to 1.0
i = 5 ; x= 1.0218971486541166 so x > DBL_MIN and x is normal and not equal to 1.0
i = 6 ; x= 1.0108892860517005 so x > DBL_MIN and x is normal and not equal to 1.0
i = 7 ; x= 1.0054299011128027 so x > DBL_MIN and x is normal and not equal to 1.0
i = 8 ; x= 1.0027112750502025 so x > DBL_MIN and x is normal and not equal to 1.0
i = 9 ; x= 1.0013547198921082 so x > DBL_MIN and x is normal and not equal to 1.0
i = 10 ; x= 1.0006771306930664 so x > DBL_MIN and x is normal and not equal to 1.0
i = 11 ; x= 1.0003385080526823 so x > DBL_MIN and x is normal and not equal to 1.0
i = 12 ; x= 1.0001692397053021 so x > DBL_MIN and x is normal and not equal to 1.0
i = 13 ; x= 1.0000846162726942 so x > DBL_MIN and x is normal and not equal to 1.0
i = 14 ; x= 1.0000423072413958 so x > DBL_MIN and x is normal and not equal to 1.0
i = 15 ; x= 1.0000211533969647 so x > DBL_MIN and x is normal and not equal to 1.0
i = 16 ; x= 1.0000105766425498 so x > DBL_MIN and x is normal and not equal to 1.0
i = 17 ; x= 1.0000052883072919 so x > DBL_MIN and x is normal and not equal to 1.0
i = 18 ; x= 1.0000026441501502 so x > DBL_MIN and x is normal and not equal to 1.0
i = 19 ; x= 1.0000013220742012 so x > DBL_MIN and x is normal and not equal to 1.0
i = 20 ; x= 1.0000006610368821 so x > DBL_MIN and x is normal and not equal to 1.0
i = 21 ; x= 1.0000003305183864 so x > DBL_MIN and x is normal and not equal to 1.0
i = 22 ; x= 1.0000001652591797 so x > DBL_MIN and x is normal and not equal to 1.0
i = 23 ; x= 1.0000000826295865 so x > DBL_MIN and x is normal and not equal to 1.0
i = 24 ; x= 1.0000000413147925 so x > DBL_MIN and x is normal and not equal to 1.0
i = 25 ; x= 1.0000000206573960 so x > DBL_MIN and x is normal and not equal to 1.0
i = 26 ; x= 1.0000000103286979 so x > DBL_MIN and x is normal and not equal to 1.0
i = 27 ; x= 1.0000000051643489 so x > DBL_MIN and x is normal and not equal to 1.0
i = 28 ; x= 1.0000000025821745 so x > DBL_MIN and x is normal and not equal to 1.0
i = 29 ; x= 1.0000000012910872 so x > DBL_MIN and x is normal and not equal to 1.0
i = 30 ; x= 1.0000000006455436 so x > DBL_MIN and x is normal and not equal to 1.0
i = 31 ; x= 1.0000000003227718 so x > DBL_MIN and x is normal and not equal to 1.0
i = 32 ; x= 1.0000000001613858 so x > DBL_MIN and x is normal and not equal to 1.0
i = 33 ; x= 1.0000000000806928 so x > DBL_MIN and x is normal and not equal to 1.0
i = 34 ; x= 1.0000000000403464 so x > DBL_MIN and x is normal and not equal to 1.0
i = 35 ; x= 1.0000000000201732 so x > DBL_MIN and x is normal and not equal to 1.0
i = 36 ; x= 1.0000000000100866 so x > DBL_MIN and x is normal and not equal to 1.0
i = 37 ; x= 1.0000000000050433 so x > DBL_MIN and x is normal and not equal to 1.0
i = 38 ; x= 1.0000000000025215 so x > DBL_MIN and x is normal and not equal to 1.0
i = 39 ; x= 1.0000000000012608 so x > DBL_MIN and x is normal and not equal to 1.0
i = 40 ; x= 1.0000000000006304 so x > DBL_MIN and x is normal and not equal to 1.0
i = 41 ; x= 1.0000000000003151 so x > DBL_MIN and x is normal and not equal to 1.0
i = 42 ; x= 1.0000000000001574 so x > DBL_MIN and x is normal and not equal to 1.0
i = 43 ; x= 1.0000000000000786 so x > DBL_MIN and x is normal and not equal to 1.0
i = 44 ; x= 1.0000000000000393 so x > DBL_MIN and x is normal and not equal to 1.0
i = 45 ; x= 1.0000000000000195 so x > DBL_MIN and x is normal and not equal to 1.0
i = 46 ; x= 1.0000000000000098 so x > DBL_MIN and x is normal and not equal to 1.0
i = 47 ; x= 1.0000000000000049 so x > DBL_MIN and x is normal and not equal to 1.0
i = 48 ; x= 1.0000000000000024 so x > DBL_MIN and x is normal and not equal to 1.0
i = 49 ; x= 1.0000000000000011 so x > DBL_MIN and x is normal and not equal to 1.0
i = 50 ; x= 1.0000000000000004 so x > DBL_MIN and x is normal and not equal to 1.0
i = 51 ; x= 1.0000000000000002 so x > DBL_MIN and x is normal and not equal to 1.0
i = 52 ; x= 1.0000000000000000 so x > DBL_MIN and x is normal and equal to 1.0
 
 
</pre>
 
=== Uwagi ===
6731

edycji