Annotation of researchv9/libc/math/hypot.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * hypot -- sqrt(p*p+q*q), but overflows only if the result does.
                      3:  * See Cleve Moler and Donald Morrison,
                      4:  * ``Replacing Square Roots by Pythagorean Sums,''
                      5:  * IBM Journal of Research and Development,
                      6:  * Vol. 27, Number 6, pp. 577-581, Nov. 1983
                      7:  */
                      8: double hypot(p, q)
                      9: double p, q;
                     10: {
                     11:        double r, s;
                     12:        if(p<0) p = -p;
                     13:        if(q<0) q = -q;
                     14:        if(p<q){ r=p; p=q; q=r; }
                     15:        if(p==0) return 0;
                     16:        for(;;){
                     17:                r=q/p;
                     18:                r*=r;
                     19:                s=r+4;
                     20:                if(s==4)
                     21:                        return p;
                     22:                r/=s;
                     23:                p+=2*r*p;
                     24:                q*=r;
                     25:        }
                     26: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.