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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:a37:4d8e:: with SMTP id a136mr9899795qkb.317.1609758832799; Mon, 04 Jan 2021 03:13:52 -0800 (PST) X-Received: by 2002:a25:db81:: with SMTP id g123mr108656979ybf.277.1609758832651; Mon, 04 Jan 2021 03:13:52 -0800 (PST) Path: eternal-september.org!reader02.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 4 Jan 2021 03:13:52 -0800 (PST) In-Reply-To: <7fe2291a-bc12-4708-85aa-0ffbdc25b2bfn@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=94.31.101.133; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf NNTP-Posting-Host: 94.31.101.133 References: <7fe2291a-bc12-4708-85aa-0ffbdc25b2bfn@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <283abde6-81b9-4194-b695-1b4686634d97n@googlegroups.com> Subject: Re: Quick inverse square root From: AdaMagica Injection-Date: Mon, 04 Jan 2021 11:13:52 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:61025 List-Id: > 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; > > function G_QUICK_INVERSE_SQRT( a : F ) return F is pragma Assert (F'Base'Size = U'Modulus); > magic : constant U := U(1.5 * 2.0**(F'Machine_Mantissa - 1) * (F(F'Machine_Emax - 1) - 0.043)); > y : F := a; > i : U; > for i'Address use y'Address; > begin > i := magic - shift_right( i, 1 ); > return y * (1.5 - (0.5 * a * y * y)); > end G_QUICK_INVERSE_SQRT;