Path: utzoo!attcan!uunet!mcvax!hafro!krafla!pierre From: pierre@rhi.hi.is (Kjartan Pierre Emilsson) Newsgroups: comp.lang.c Subject: Re: floating point constants Message-ID: <1066@krafla.rhi.hi.is> Date: 28 Jul 89 11:42:07 GMT References: <14675@dartvax.Dartmouth.EDU> Organization: University of Iceland Lines: 35 From article <14675@dartvax.Dartmouth.EDU>, by ari@eleazar.dartmouth.edu (Ari Halberstadt): > In article <1925@arisia.Xerox.COM> leisner@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.