sqt.c

Go to the documentation of this file.
00001 /*
00002  * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
00003  * See the copyright notice in the ACK home directory, in the file "Copyright".
00004  *
00005  * Author: Ceriel J.H. Jacobs
00006  */
00007 
00008 /* $Header: /opt/proj/minix/cvsroot/src/lib/ack/libp/sqt.c,v 1.1 2005/10/10 15:27:47 beng Exp $ */
00009 #define __NO_DEFS
00010 #include <math.h>
00011 #include <pc_err.h>
00012 extern  _trp();
00013 
00014 #define NITER   5
00015 
00016 static double
00017 Ldexp(fl,exp)
00018         double fl;
00019         int exp;
00020 {
00021         extern double _fef();
00022         int sign = 1;
00023         int currexp;
00024 
00025         if (fl<0) {
00026                 fl = -fl;
00027                 sign = -1;
00028         }
00029         fl = _fef(fl,&currexp);
00030         exp += currexp;
00031         if (exp > 0) {
00032                 while (exp>30) {
00033                         fl *= (double) (1L << 30);
00034                         exp -= 30;
00035                 }
00036                 fl *= (double) (1L << exp);
00037         }
00038         else    {
00039                 while (exp<-30) {
00040                         fl /= (double) (1L << 30);
00041                         exp += 30;
00042                 }
00043                 fl /= (double) (1L << -exp);
00044         }
00045         return sign * fl;
00046 }
00047 
00048 double
00049 _sqt(x)
00050         double x;
00051 {
00052         extern double _fef();
00053         int exponent;
00054         double val;
00055 
00056         if (x <= 0) {
00057                 if (x < 0) _trp(ESQT);
00058                 return 0;
00059         }
00060 
00061         val = _fef(x, &exponent);
00062         if (exponent & 1) {
00063                 exponent--;
00064                 val *= 2;
00065         }
00066         val = Ldexp(val + 1.0, exponent/2 - 1);
00067         /* was: val = (val + 1.0)/2.0; val = Ldexp(val, exponent/2); */
00068         for (exponent = NITER - 1; exponent >= 0; exponent--) {
00069                 val = (val + x / val) / 2.0;
00070         }
00071         return val;
00072 }

Generated on Fri Apr 14 22:57:25 2006 for minix by  doxygen 1.4.6