Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Math library functions and error checking Message-ID: <1990May7.223555.5275@utzoo.uucp> Organization: U of Toronto Zoology References: <1323@tub.UUCP> Date: Mon, 7 May 90 22:35:55 GMT In article <1323@tub.UUCP> net@tub.UUCP (Oliver Laumann) writes: >What is the correct method to check whether an exception (overflow, >invalid arguments, etc.) occurred during the execution of a C math >library function (such as sqrt() or sin())? > >Do I have to test the result against NaN, or do I have to check errno >(EDOM)? If the latter is true, is errno cleared automatically on >success or do I have to clear it before calling the function? There is no simple, uniform, standard way of testing for trouble in the math functions. You have to look at the return value of each function in combination with errno. No, the functions do not clear errno on success, and in certain circumstances they are not guaranteed to set it on failure. No, they do not return NaN, since that is not a fully portable concept. The whole area is kind of a mess, especially since even the unsatisfactory existing state of things does not satisfy the high-performance fanatics, who would prefer (last I heard) to get back something like a NaN rather than having to test values and flags every time. There are people looking at better approaches. -- If OSI is the answer, what is | Henry Spencer at U of Toronto Zoology the question?? -Rolf Nordhagen| uunet!attcan!utzoo!henry henry@zoo.toronto.edu