Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | "James Van Buskirk" <not_valid@comcast.net> |
|---|---|
| Newsgroups | comp.arch |
| Subject | Re: NR reciprocal/division without extended precision |
| Date | 2016-01-24 10:29 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <n831ib$505$1@dont-email.me> (permalink) |
| References | <0eb97c14-d5ac-4e93-b063-1d1eba7831e1@googlegroups.com> |
> wrote in message > news:0eb97c14-d5ac-4e93-b063-1d1eba7831e1@googlegroups.com... > I make it a separate thread. > me: > Another problem with pure software NR reciprocal that I found > yesterday: For y=(2^53-1)/2^53 NR converges to x=1 instead of > correct value of x=(2^52+1)/2^52. So, some preventive measures > should be taken. For me, setting few LSBs to 1 before last NR > iterations worked fine. I suppose, it is known in the literature, > but I didn't read literature, just saw James's post and started hacking. > James Van Buskirk: > Check your arithmetic above. N-R is only out by 0.5 ulps actually, > not 1.0 ulps. Getting from 0.5+epsilon down to 0.5-epsilon is > about as hard as it was to get the right answer in the first place. > I checked my arithmetic above. And indeed my emulation of > FMA by means of Gnu float128 was broken. It suffered from > double rounding. I tested several implementations of > C99/C++11 fma() library function under Windows/x64/IvyBridge. > Unfortunately, all of them were broken. Some, like > MINGW/MINGW64, were broken in rude obvious way. Others, > like VS3013, were broken in more subtle manner. But I didn't > find one that works. So, I rolled my own. It's possible that it is > broken too, but I don't think so. > So, I tested my statement above with supposedly good FMA > and it still appears correct. That is, if, by chance, we hit a > correct value (x=(2^52+1)/2^52) as an initial approximation > then we will stay here. If, however, the initial value is anything > else then NR iterations will converge to 1.0 which is incorrect. > To be more specific, I tested only form of NR steps used by > James on the first and last steps, i.e: > err = fma(-y, x, 1.0); > x = fma(x, err, x); There seems to be some sort of theorem that you need 2*n+1 bits of accuracy to get to n bit rounded perfectly. http://www.informatik.uni-trier.de/Reports/TR-08-2004/rnc6_12_markstein.pdf I haven't read that very carefully. The error in your example is almost exactly the same whichever way the final rounding goes, 0.5 ulps. I'm not sure whether the above paper requires some kind of extended precision to get the perfect rounding that you desire. Some might say that the perfect should not get in the way of the pretty darned good, and in the only application I have seen that is reciprocal throughput limited (polynomial evaluation by barycentric interpolation in chebfun) perfect rounding is not a requirement. You might be able to capture 2*n+1st bit without extended precision. Take err from your equation above and from it build capture by copying the exponent bits, maybe the sign bit, and wiping out all the mantissa bits but setting the lowest manitssa bit. Then add err**2 to capture so that round to nearest even will capture that low bit if it's there, then subtract the original capture and finally add to err. Then I think your final fma might do what you want.
Back to comp.arch | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
NR reciprocal/division without extended precision already5chosen@yahoo.com - 2016-01-24 08:36 -0800
Re: NR reciprocal/division without extended precision "James Van Buskirk" <not_valid@comcast.net> - 2016-01-24 10:29 -0700
Re: NR reciprocal/division without extended precision MitchAlsup <MitchAlsup@aol.com> - 2016-01-24 09:46 -0800
Re: NR reciprocal/division without extended precision already5chosen@yahoo.com - 2016-01-28 01:16 -0800
Re: NR reciprocal/division without extended precision Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-28 21:01 +0100
Re: NR reciprocal/division without extended precision already5chosen@yahoo.com - 2016-01-28 14:49 -0800
Re: NR reciprocal/division without extended precision Terje Mathisen <terje.mathisen@tmsw.no> - 2016-01-29 07:38 +0100
csiph-web