Use of C99 extra long double math functions after r236148

Stephen Montgomery-Smith stephen at missouri.edu
Sun Aug 12 23:08:49 UTC 2012


On 07/18/2012 09:53 PM, Steve Kargl wrote:
> On Wed, Jul 18, 2012 at 04:09:06PM -0500, Stephen Montgomery-Smith wrote:
>> On 07/18/2012 03:56 PM, Steve Kargl wrote:
>>> On Wed, Jul 18, 2012 at 10:07:41AM -0500, Stephen Montgomery-Smith wrote:
>>>>
>>>>> The most obvious immediate difficulty in translating the above into C is
>>>>> that y*y and z*z may overflow when the result shouldn't.
>>>>
>>>> This will be a lot easier than I originally expected.  When we are in
>>>> conditions when overflow might occur, we can simply make the
>>>> approximations
>>>> sqrt(y*y-1) = y
>>>> csqrt(z*z+1) = signum(x)*z
>>>> because in floating point arithmetic, these will not be approximations,
>>>> but true exactly.  And I am thinking that the test I will use for when
>>>> to use these approximations will be (y==y+1) and (z==z+1) respectively.
>>>>   (I would use (z*z==z*z+1) but that test has the overflow problem.)
>>>
>>> I could be mistaken, but I believe that you need to raise the
>>> inexact flag with these approximations because in fact you
>>> are doing floating point math.
>>>
>>
>> Thanks for this observation.  I am looking through the C99 standard,
>> trying to understand the inexact flag.  But I am struggling to interpret it.
>>
>> Am I to understand that the inexact flag should be set anytime a
>> floating point operation produces an answer that is not guaranteed
>> exact?  For example, should 1.0/3.0 and sqrt(2.0) raise the inexact flag?
>
> The inexact flag will get raised by the fpu, but you need to
> cause the condition.  For your 'sqrt(y*y-1) = y' example,
> you would do something like 'sqrt(y*y-1) = abs(y) - tiny' where
> tiny is much less than abs(y).   Search msun/src for inexact
> (ie., grep -i inexact msun/src/*.c)
>

Couldn't you do this instead?

#include <fenv.h>

feraiseexcept(FE_INEXACT)






More information about the freebsd-numerics mailing list