Hi,

A good read on the subject of square roots :

A Perfect Square Root Routine
E.E. McDonnell
http://www.jsoftware.com/papers/eem/sqrt.htm

On Thu, Nov 1, 2018 at 3:32 PM Raul Miller <[email protected]> wrote:

> Square roots cannot (in the typical case) be represented using
> extended precision numbers (which are integers).
>
>    a=:1234567890101020405060708090x
>    a^1r2
> 3.51364e13
>    datatype a^1r2
> floating
>
> This floating representation represents numbers using a representation of
>    sign * 1+fraction * 2^exponent
>
> This all fits into a 64 bit representation with one bit for sign
> (choosing from 1 or _1), 52 bits for the fraction, and the remaining
> 11 bits for the exponent (with a few exponent values reserved for
> handling infinities and "NaN" numbers). (All arranged so that the same
> less than / greater than logic used for integers will also work for
> floating point numbers.)
>
> But the (a) value is not a square number:
>
>    __ q: a
> 2 5 211 461 23339 54381270850093261
> 1 1   1   1     1                 1
>
> If it were square, the values in the second row of that result would
> all be even numbers.
>
> So that means that a precise representation of the square root would
> take an infinite number of bits in the floating point fraction, which
> is more than the 52 bits which get used.
>
> Anyways, if you want a better approximation of the square root, you'd
> probably use the floating point value as a starting point and then use
> some algorithm to improve that estimate until it seems good enough.
>
> --
> Raul
>
>
>
>
>
> FYI,
>
> --
> Raul
> On Thu, Nov 1, 2018 at 3:13 PM Skip Cave <[email protected]> wrote:
> >
> > a=:1234567890101020405060708090x
> >
> >
> > a=2^~a^1r2
> >
> > 1
> >
> > a=2^~%:a
> >
> > 1
> >
> > a-:2^~a^1r2
> >
> > 1
> >
> > a-:2^~%:a
> >
> > 1
> >
> >
> > NB. All looking good. However:
> >
> >
> > x:2^~a^1r2
> >
> > 1234567890101024064259751936
> >
> > a
> >
> > 1234567890101020405060708090
> >
> >
> > NB. Clearly not equal.
> >
> >
> > x:2^~%:a
> >
> > 1234567890101020490846961664
> >
> > a
> >
> > 1234567890101020405060708090
> >
> >
> > NB. Also clearly not equal, and different from the first one!
> >
> >
> > What's going on!
> >
> >
> > Skip
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to