From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Quick inverse square root Date: Mon, 4 Jan 2021 13:13:00 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <7fe2291a-bc12-4708-85aa-0ffbdc25b2bfn@googlegroups.com> <283abde6-81b9-4194-b695-1b4686634d97n@googlegroups.com> NNTP-Posting-Host: 5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:61027 List-Id: On 2021-01-04 12:28, AdaMagica wrote: > AdaMagica schrieb am Montag, 4. Januar 2021 um 12:13:53 UTC+1: >>> with INTERFACES; use INTERFACES; >>> generic >>> type F is digits <>; >>> type U is mod <>; >>> with function SHIFT_RIGHT( n : U; amount : NATURAL ) return U; >>> function G_QUICK_INVERSE_SQRT( a : F ) return F; > > I haven't got the slightest idea for which range this function should be applied, but for sure not for the complete Float range. > Thus there should be an assertion about the range of the parameter a in the body. Or even better a precondition in the spec. It appears to be the Newton method with an heuristic used to choose the starting point. The descriptions is here: https://en.wikipedia.org/wiki/Fast_inverse_square_root It also mentions a hack for double precision IEEE 754 floats. P.S. The method makes no sense to implement or use on modern hardware. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de