Re: [math-fun] Origin of SQRT hack?
FYI -- http://dspace.mit.edu/bitstream/handle/1721.1/6128/AIM-103.pdf?sequence=2 MIT Project MAC AI Project Vision Project Internal Memo No. 103. August 2, 1966 ... SQRT INPUT LISP number x. OUTPUT LISP number sqrt(x). ALARMS None. ALGORITHM Four iterations of Newton's method with first approximation as x/2^floor(log2(x)/2), i.e., the floating exponent is divided by 2. AVAILABILITY Same as ABS and ANGBTN. ... [I'm using slightly more modern notation, rather than trying to post a jpg or png image.] At 04:52 PM 4/15/2011, rcs@xmission.com wrote:
I think I remember seeing this in the PDP6 library function for sqrt. I believe the shift was followed by adding (integer add) a magic constant, probably to adjust the range and repair the exponent offset. Then a few rounds of Newton, unwound.
(note to folks under 50) Before IEEE floating point came along, the individual computer makers had their own formats for floating point. Both the 7090 series and PDP6/10 used 36-bit words. The PDP6 format had 8 bits of exponent, offset by 128, and 27 bits of mantissa. A normalized number included the high-order 1 bit, which is dropped in IEEE format. I don't recall if that bit had value .5 or 1.0. 0.0 was simply 0, and negatives were the (integer) two's complement of the positives. This had the virtue that the ordering of (normalized) floating numbers was the same as the ordering of integers, so the compare instructions didn't need to come in two flavors.
I think I'll register a disagreement with the comment that IEEE accuracy requirements for sqrt (exactly correct rounding) effectively preclude doing it in software: After a few rounds of Newton, the answer should be within one bit, likely on the high side. You can check which of two consecutive floating values is correct by comparing V * (V-epsilon) versus X.
Rich
---- Quoting Bill Gosper <billgosper@gmail.com>:
hgb>When making an initial guess of sqrt(x) for a Newton iteration, where x is a positive floating point number, a good initial guess is the bits of the entire number (both exponent & mantissa) shifted right by 1.
This is the sort of thing that would have been done on the 7090 or the PDP-10. Does anyone here recall seeing this trick in the 1950's or 1960's ?
I checked, and it isn't in HAKMEM.
I've used this trick myself (at least on machines where moving numbers between the integer & floating point units isn't prohibitive). ------ rwg>It's really old, and can probably be found in the 704 and pdp-6 library sqrts. I think Knuth told me he found it as an undergrad, but that basketball youtube shows him using a biquinary machine (650?). --rwg
participants (1)
-
Henry Baker