FE_UNDERFLOW w c

Bash, C, C++, Java, PHP, Ruby, GTK, Qt i wiele innych - wszystko tutaj.
adammaj1
Piegowaty Guziec
Piegowaty Guziec
Posty: 29
Rejestracja: 25 gru 2011, 12:37
Płeć: Mężczyzna
Wersja Ubuntu: 13.10
Środowisko graficzne: GNOME
Architektura: x86_64

FE_UNDERFLOW w c

Post autor: adammaj1 »

Chciałęm sprawdzić wyjątki w obliczeniach numerycznych. Mam program który testuje coraz mniejsze , dodatnie licznby : czy są subnormalne, równe zero i czy powstaje FP_UNDERFLOW. Tutaj jest program

Kod: Zaznacz cały

#include <math.h> /* isnormal */
#include <float.h>//DBL_MIN
#include <stdio.h>
//#include <signal.h>
#include <fenv.h> // floating point envirement


int TestNumber(double x)
{
      
       
      //
      if (x<DBL_MIN) printf ("x < DBL_MIN and ");
          else printf ("x > DBL_MIN  and  ");
      //
      if (isnormal(x)) printf ("x is normal and ");
            else printf ("x is subnormal and ");

      //
      if (x==0.0) printf ("equal to 0.0 ; ");
      else printf ("not equal to 0.0 ; ");
      //
      
      if (fetestexcept(FE_UNDERFLOW)!=0) 
      {printf ("FE_UNDERFLOW = %d \n", FE_UNDERFLOW); return 1;}
      else printf ("no UNDERFLOW \n" ); 
 
      return 0; 
      
     
}



int main ()
{
       double x=1.0;
       int raised;
        
  int i;
  for ( i=0; i < 330; i++)
    {

      //
      printf ("i = %3d ; x= %.16lf = %e so  ", i, x, x);
      raised = TestNumber(x);
      //if (raised!=0) {  return raised ;}
      feclearexcept (FE_ALL_EXCEPT);  
      x/=10;
  
          
    }

        
       

return 0; 

     }
a tu wynik :

Kod: Zaznacz cały

    i = 299 ; x= 0.0000000000000000 = 1.000000e-299 so  x > DBL_MIN  and  x is normal and not equal to 0.0 ; no UNDERFLOW 
    i = 300 ; x= 0.0000000000000000 = 1.000000e-300 so  x > DBL_MIN  and  x is normal and not equal to 0.0 ; no UNDERFLOW 
    i = 301 ; x= 0.0000000000000000 = 1.000000e-301 so  x > DBL_MIN  and  x is normal and not equal to 0.0 ; no UNDERFLOW 
    i = 302 ; x= 0.0000000000000000 = 1.000000e-302 so  x > DBL_MIN  and  x is normal and not equal to 0.0 ; no UNDERFLOW 
    i = 303 ; x= 0.0000000000000000 = 1.000000e-303 so  x > DBL_MIN  and  x is normal and not equal to 0.0 ; no UNDERFLOW 
    i = 304 ; x= 0.0000000000000000 = 1.000000e-304 so  x > DBL_MIN  and  x is normal and not equal to 0.0 ; no UNDERFLOW 
    i = 305 ; x= 0.0000000000000000 = 1.000000e-305 so  x > DBL_MIN  and  x is normal and not equal to 0.0 ; no UNDERFLOW 
    i = 306 ; x= 0.0000000000000000 = 1.000000e-306 so  x > DBL_MIN  and  x is normal and not equal to 0.0 ; no UNDERFLOW 
    i = 307 ; x= 0.0000000000000000 = 1.000000e-307 so  x > DBL_MIN  and  x is normal and not equal to 0.0 ; no UNDERFLOW 
    i = 308 ; x= 0.0000000000000000 = 1.000000e-308 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 309 ; x= 0.0000000000000000 = 1.000000e-309 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; no UNDERFLOW 
    i = 310 ; x= 0.0000000000000000 = 1.000000e-310 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 311 ; x= 0.0000000000000000 = 1.000000e-311 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 312 ; x= 0.0000000000000000 = 1.000000e-312 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 313 ; x= 0.0000000000000000 = 1.000000e-313 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 314 ; x= 0.0000000000000000 = 1.000000e-314 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 315 ; x= 0.0000000000000000 = 1.000000e-315 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 316 ; x= 0.0000000000000000 = 1.000000e-316 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 317 ; x= 0.0000000000000000 = 9.999997e-318 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 318 ; x= 0.0000000000000000 = 9.999987e-319 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 319 ; x= 0.0000000000000000 = 9.999889e-320 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 320 ; x= 0.0000000000000000 = 9.999889e-321 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; no UNDERFLOW 
    i = 321 ; x= 0.0000000000000000 = 9.980126e-322 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 322 ; x= 0.0000000000000000 = 9.881313e-323 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 323 ; x= 0.0000000000000000 = 9.881313e-324 so  x < DBL_MIN and x is subnormal and not equal to 0.0 ; no UNDERFLOW 
    i = 324 ; x= 0.0000000000000000 = 0.000000e+00 so  x < DBL_MIN and x is subnormal and equal to 0.0 ; FE_UNDERFLOW = 16 
    i = 325 ; x= 0.0000000000000000 = 0.000000e+00 so  x < DBL_MIN and x is subnormal and equal to 0.0 ; no UNDERFLOW 
    i = 326 ; x= 0.0000000000000000 = 0.000000e+00 so  x < DBL_MIN and x is subnormal and equal to 0.0 ; no UNDERFLOW 
    i = 327 ; x= 0.0000000000000000 = 0.000000e+00 so  x < DBL_MIN and x is subnormal and equal to 0.0 ; no UNDERFLOW 
    i = 328 ; x= 0.0000000000000000 = 0.000000e+00 so  x < DBL_MIN and x is subnormal and equal to 0.0 ; no UNDERFLOW 
    i = 329 ; x= 0.0000000000000000 = 0.000000e+00 so  x < DBL_MIN and x is subnormal and equal to 0.0 ; no UNDERFLOW 
Czemu zachwownie FE_UNDERFLOW nie jest takie samo dla liczb subnormalnych ?
ODPOWIEDZ

Wróć do „Programowanie”

Kto jest online

Użytkownicy przeglądający to forum: Obecnie na forum nie ma żadnego zarejestrowanego użytkownika i 15 gości