How can I compute the range of signed and unsigned types

Florent Calvayrac fcalvay at aviion.univ-lemans.fr
Wed Apr 18 05:03:14 PDT 2001


Chris Richard Adams wrote:
> 
> How can I 'compute' the different sizes of types on the machine?  to
> prove that the values within limits.h are valid.  I also would like to
> do this for reals. Anyone have any tips - I'd appreciate it.
> 
> Thanks,
> Chris
>

hi 

I tease my students with the following piece
of ugly  C code (coming I think from ENS Lyon and IMAG)
try it on your pocket calculator and see the difference...


#include<stdio.h>
void
whoami(float *b, int *c)
{
        float a;
        for(a=1.0;((a+1.0)-a)-1.0==0.0;a=2.0*a)  ;
        for(*b=1.0;((a+*b)-a)-*b!=0.0;*b=*b+1.0)   ;
        *c=0;
        for(a=1.0;((a+1.0)-a)-1.0==0.0;(*c)++) a=*b*a;
}

int
main()
{
        float x;
        int i;
        whoami(&x,&i);
        printf("x=%f , i=%i\n",x,i);
        return(0);              

}

-- 
Florent Calvayrac                          | Tel : 02 43 83 26 26 
Laboratoire de Physique de l'Etat Condense | Fax : 02 43 83 35 18
UMR-CNRS 6087         | http://www.univ-lemans.fr/~fcalvay 
Universite du Maine-Faculte des Sciences   |
72085 Le Mans Cedex 9





More information about the Beowulf mailing list