Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Aug 2012 23:09:26 -0000
From:      Bruce Evans <brde@optusnet.com.au>
To:        Stephen Montgomery-Smith <stephen@missouri.edu>
Cc:        Diane Bruce <db@db.net>, Bruce Evans <brde@optusnet.com.au>, John Baldwin <jhb@freebsd.org>, David Chisnall <theraven@freebsd.org>, Bruce Evans <bde@freebsd.org>, Steve Kargl <sgk@troutmask.apl.washington.edu>, David Schultz <das@freebsd.org>, Peter Jeremy <peter@rulingia.com>, Warner Losh <imp@bsdimp.com>
Subject:   Re: Use of C99 extra long double math functions after r236148
Message-ID:  <20120720035001.W4053@besplex.bde.org>
Resent-Message-ID: <20120812230919.GN20453@server.rulingia.com>
In-Reply-To: <50084322.7020401@missouri.edu>
References:  <20120714120432.GA70706@server.rulingia.com> <20120717084457.U3890@besplex.bde.org> <5004A5C7.1040405@missouri.edu> <5004DEA9.1050001@missouri.edu> <20120717200931.U6624@besplex.bde.org> <5006D13D.2080702@missouri.edu> <20120718205625.GA409@troutmask.apl.washington.edu> <500725F2.7060603@missouri.edu> <20120719025345.GA1376@troutmask.apl.washington.edu> <50077987.1080307@missouri.edu> <20120719032706.GA1558@troutmask.apl.washington.edu> <5007826D.7060806@missouri.edu> <5007AD41.9070000@missouri.edu> <20120719205347.T2601@besplex.bde.org> <50084322.7020401@missouri.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 19 Jul 2012, Stephen Montgomery-Smith wrote:

> I have the ULP down to about 1.2 now.  I don't see how I can do better, 
> because I have to invoke log functions twice, and probably each one has a ULP 
> of about 0.6.
>
> Also I decided to use 1/2 log(x*x+y*y) when x and y are not too large.

That's close to Apple complex.c clog().  Once you don't use hypot(),
it is clearly best to use log1p():

 	log(sqrt(x*x + y*y)) = log(|x|) + 1/2 log(1 + (y*y)/(x*x))
 			     = log(|x|) + 1/2 log1p((y*y)/(x*x))

where |x| >= |y| so that log1p()'s arg is as small as possible.

> I am really rather proud of how I got around the large ULP when hypot(x,y) is 
> close to 1.  I would be glad if any of you could look at the code when you 
> get a chance.

WIll look more closely later.  I see that you already use log1p() and much
more.  Apple clog() uses not so much more, mainly by depending on extra
precision in hardware.  The above also avoids overflow and use of hypot()
for all finite x and and y, but is probably too simple.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120720035001.W4053>