Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6908
| From | Jan Burse <janburse@fastmail.fm> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: higher precision doubles |
| Date | 2011-08-09 12:52 +0200 |
| Organization | albasani.net |
| Message-ID | <j1r3h1$v0p$1@news.albasani.net> (permalink) |
| References | (13 earlier) <j1nbr7$h7r$1@dont-email.me> <j1o1sk$427$1@news.albasani.net> <j1pif0$lr4$1@news.albasani.net> <j1pq9c$6d0$1@news.albasani.net> <j1qvqa$mti$1@news.albasani.net> |
BGB schrieb:
> yes, but try to find a good way to directly calculate x/y...
> it is a much easier problem to calculate x*(1.0/y)...
>
>
> Newton's Method is a reasonably good way to calculate 1.0/y, and in my
> case (with 128-bit floats), usually manages to converge in approx 12
> iterations.
>
>
> here is some code from my own implementation (in C):
>
> fv128_t fv128_rcp(fv128_t a)
> {
> fv128_t f, g, xo, xn;
> int i;
>
> if(fv128_eq1p(a))
> return(a);
>
> i=fv128_getExponent(a);
> xo=fv128_pow2x(fv128_const_one, -i);
>
> for(i=0; i<100; i++)
> {
> f=fv128_mul(a, xo);
> g=fv128_sub(fv128_const_two, f);
> xn=fv128_mul(xo, g);
> if(fv128_eqp(xo, xn))
> return(xn);
> xo=xn;
> }
> return(xn);
> }
>
> fv128_t fv128_div(fv128_t a, fv128_t b)
> {
> return(fv128_mul(a, fv128_rcp(b)));
> }
>
>
>
> <snip>
Yeah good old Newton.
f(x) = a - 1/x.
zero at: 1/a.
f'(x) = 1 / x^2.
x_n+1 = x_n - f(x_n)/f'(x_n)
= x_n - (a - 1/x_n) / (1/x_n^2)
= x_n - a * x_n^2 + x_n
= x_n * (2 - a * x_n)
But diverge or stays constant in certain intervals.
Here for a=1.5:
x_1=-2/3: Asymptotically reaches -inf
x_1=-1/3: Asymptotically reaches -inf
x_1=0: Stays constant at 0
x_1=1/3: Converges to 2/3
x_1=2/3: Converges to 2/3
x_1=1: Converges to 2/3
x_1=1 1/3: Stays constant at 0 after x_2
x_1=1 2/3: Asymptotically reaches -inf
And does eventually not converge very good:
x_1=0.0001: Slowly recovers
x_1=1 1/3 + 0.0001: Slowly recovers
Hope your initial pick is good.
Bye
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-06 00:20 +0200
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-06 03:35 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-06 13:03 +0200
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-06 12:20 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-06 23:30 +0200
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-06 16:12 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 01:35 +0200
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-06 19:26 -0700
Re: higher precision doubles supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-08-09 00:42 -0400
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-09 04:07 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-09 14:00 +0200
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-09 09:07 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-10 08:50 +0200
Re: higher precision doubles supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-08-10 20:16 -0400
Re: higher precision doubles Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-09 10:11 -0500
Re: higher precision doubles Arne Vajhøj <arne@vajhoej.dk> - 2011-08-09 22:40 -0400
Re: higher precision doubles Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-09 22:06 -0500
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-10 08:53 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-06 21:24 +0200
Re: higher precision doubles markspace <-@.> - 2011-08-06 13:29 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-06 23:20 +0200
Re: higher precision doubles markspace <-@.> - 2011-08-06 15:43 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 01:06 +0200
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-06 16:21 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 01:34 +0200
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-06 21:32 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 17:24 +0200
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 17:39 +0200
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-07 09:26 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 21:23 +0200
Re: higher precision doubles Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-07 20:48 -0400
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-08 09:05 +0200
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-08 05:37 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-08 19:08 +0200
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-08 19:16 +0200
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-08 19:29 +0200
Re: higher precision doubles Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-08 21:34 -0500
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-08 13:49 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-09 01:08 +0200
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-09 02:44 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-09 12:52 +0200
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-09 13:15 -0700
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-07 13:51 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 01:59 +0200
Re: higher precision doubles Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-08 21:03 -0500
Re: higher precision doubles Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-06 17:33 -0400
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-06 14:51 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 00:57 +0200
csiph-web