floating point constants

Kjartan Pierre Emilsson pierre at rhi.hi.is
Fri Jul 28 21:42:07 AEST 1989


>From article <14675 at dartvax.Dartmouth.EDU>, by ari at eleazar.dartmouth.edu (Ari Halberstadt):
> In article <1925 at arisia.Xerox.COM> leisner at arisia.Xerox.COM (Marty Leisner) writes:
>>Is this a valid C program?  gcc 1.35 handles it fine on a sun386i --
>>main()
>>{
>>        printf("%f\n", 1.0/0.0);
>>        printf("%f\n", -1.0/0.0);
>>        printf("%f\n", 0.0/0.0);
>>}
> 
> Why on earth would anyone want to compile that :-)?
> I think it's quite legal C, but it's total giberish, since if the compiler
> compiled it, it would simply result in a divide by zero, which any normal
> maching would have a fit over.

Not so.  If your math library uses IEEE floating point standard, then the 
following code will work perfectly:

		main()
		{
			double a,b,c;
			extern double atan();

			a=1.0;
			b=0.0;
			c=a/b;
			c=atan(c);
			printf("%f\n",c);
		}

and the output will be:

		1.57080     ( That is: Pi/2 which is arctangens(infinity)!)

I'm not sure wether this is a good behaviour to rely upon, but it works.



More information about the Comp.lang.c mailing list