Date: Tue, 7 Feb 1995 01:57:06 -0400 (AST) From: Bill Davidson Subject: Re: How to use Inf and NaN? To: Papp Istvan Cc: djgpp AT sun DOT soe DOT clarkson DOT edu On Wed, 1 Feb 1995, Papp Istvan wrote: > Hi! > I have a 486DX2-50 machine with MS DOS 6.22, and I use gcc 2.60. > I'd like to use Inf and NaN with djgpp as a regular number. For > example: > x= log(0.0) > results in floating point exception, but I would be very happy > if -Inf was stored into x. > Another example: > x= 0.0 / 0.0 > also generates floating point example, but I need NaN in x. > > Is there any solution for this problem? > > Thanx in advance, > Pisti I haven't seen any replies posted, so, with much trepidation, I decided to take a look at this problem. I thought the ANSI standard signal() function might be a good approach, since it lets you set up your own exception handler for floating point exceptions. However, a look at the libc.a docs indicated that the various signal() functions are not implemented, except to return an error condition. I am in no way competent to even begin to try to roll my own signal(), so that's out. That leaves assembly language, and modifying the FPU contol word to mask off certain exceptions, including divide by zero and whatever other conditions could result in a NaN. Then no exceptions will be generated. However, this is very dangerous, and any finit (say, in a library function) will reset the control word to the default state. Note that you can also set the FPU's internal representation of infinity to affine or projective, but I have never found a good description of what these are (!), nor have I ever tried it and watched the stack to see. The default state is, I believe, affine, but if you want to use the result as above maybe projective would be better???? A look at the header files also revealed that the matherr() function is only available under C++; I don't think it is what you wanted anyway. Still, I guess it would work in the first case since you are talking about a domain error in a library function. You might give it a try; check the docs, see what you come up with, and let me know how it work out. Bill Davidson bdavidson AT ra DOT isisnet DOT com