From: Dave Pederson Date: 2007-08-25T02:30:29+09:00 Subject: Re: Inverse Square Root ------=_Part_88894_10663317.1187976627101 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Yes they are. I remembered (after the fact) that it is an approximation algorithm and probably doesn't make sense to include in Ruby. To get more accurate results you would have to run the following line a couple times: x = x*(1.5f - xhalf*x*x); But still...the results will be incorrect or rough. It is actually slower too (at least the way I coded it): When calculating the inverse square root with my Math.isqrt(), the value was 0.999995648860931 and it took 4.0E-6 seconds When calculating the inverse square root with 1.0/Math.sqrt(), the value was 1.0 and it took 3.0E-6 seconds I guess the fast inverse square root would only make sense to include iff someone needed an approximation that didn't rely on division. Thanks, -Dave On 8/24/07, Nobuyoshi Nakada wrote: > > Hi, > > At Fri, 24 Aug 2007 15:28:26 +0900, > Dave Pederson wrote in [ruby-core:11981]: > > Which gave the following results (which seem correct): > > > > 1 - 0.998307168483734 > > 4 - 0.499153584241867 > > 9 - 0.332953214645386 > > 16 - 0.249576792120934 > > Seem incorrect or quite rough. > > -- > Nobu Nakada > > ------=_Part_88894_10663317.1187976627101 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Yes they are.  I remembered (after the fact) that it is an approximation algorithm and probably doesn't make sense to include in Ruby.  To get more accurate results you would have to run the following line a couple times:

x = x*(1.5f - xhalf*x*x);

But still...the results will be incorrect or rough.  It is actually slower too (at least the way I coded it):

When calculating the inverse square root with my Math.isqrt(), the value was 0.999995648860931 and it took  4.0E-6 seconds
When calculating the inverse square root with 1.0/Math.sqrt(), the value was 1.0 and it took  3.0E-6 seconds

I guess the fast inverse square root would only make sense to include iff someone needed an approximation that didn't rely on division.

Thanks,

-Dave

On 8/24/07, Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:
Hi,

At Fri, 24 Aug 2007 15:28:26 +0900,
Dave Pederson wrote in [ruby-core:11981]:
> Which gave the following results (which seem correct):
>
> 1 - 0.998307168483734
> 4 - 0.499153584241867
> 9 - 0.332953214645386
> 16 - 0.249576792120934

Seem incorrect or quite rough.

--
Nobu Nakada


------=_Part_88894_10663317.1187976627101--