Date: Fri, 29 Aug 2003 17:01:17 -0500 From: Eric Rudd Subject: Re: Arithmetic Exceptions in C99 In-reply-to: <3F4FC482.A71D96A1@phekda.freeserve.co.uk> To: djgpp-workers AT delorie DOT com Message-id: <3F4FCD2D.5070204@cyberoptics.com> Organization: CyberOptics MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7bit X-Accept-Language: en,pdf User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.3) Gecko/20030312 References: <200308292046 DOT h7TKkAEJ012781 AT speedy DOT ludd DOT luth DOT se> <3F4FC482 DOT A71D96A1 AT phekda DOT freeserve DOT co DOT uk> X-MailScanner-Information: Please contact the ISP for more information X-MailScanner: Found to be clean Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk Richard Dawe wrote: >ams AT ludd DOT luth DOT se wrote: > > >>For me raise an exception == generate a signal. Both Eli and you >>seems to say that raising an exception is something else than >>generating a signal. >> >>Can somebody explain this to me? >> >> >I think you're confusing the word "exception" in maths terms with "exceptions" >represented by SIG*. In the case of the maths "exceptions" I think the >exception is signalled by setting a bit in some exception register somewhere. >See section 7.6.1 (FE_* constants like FE_INVALID) and section 7.6.2 of the >C99 standard. > >(That's from a quick read of the sections mentioned. I may be wrong.) > > I have posted a question to comp.std.c where I've asked what "floating-point exception" means in terms of the standard, among other things. It appears to me that the committee members had in their minds something like the exception bits in the floating-point status word of the x87, but of course they can't say that in the standard; one has to access the bits through standard C functions and variables. I've also asked comp.std.c how we can have "floating-point exceptions" required in Annex F for math functions when, as I noted earlier, the standard requires the math functions to complete without any "externally visible exceptional conditions". I am still of the opinion that it is best to prevent the math functions from either raising signals or setting exception bits in the FPU status register, because they can crash a program and prevent recovery. On the other hand, in the comp.std.c archives one person noted that errno was very inefficient on some processors, and that the C committee wanted to have another mechanism for trapping errors, so they included the exception mechanism in C99. (The errno mechanism is now optional, and there are macros in a header file to indicate whether it works or not.) Fortunately, we only have the Intel platform to deal with. In coding the math functions several years ago, I saw that there was a certain inefficiency involved in identifying error conditions, but it was possible to bias the tests in favor of quick fall-through for normal arguments, so that the time hit was only about 10%. -Eric Rudd rudd AT cyberoptics DOT com