source: trunk/minix/lib/ack/libp/sqt.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.2 KB
Line 
1/*
2 * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
4 *
5 * Author: Ceriel J.H. Jacobs
6 */
7
8/* $Header: /cvsup/minix/src/lib/ack/libp/sqt.c,v 1.1 2005/10/10 15:27:47 beng Exp $ */
9#define __NO_DEFS
10#include <math.h>
11#include <pc_err.h>
12extern _trp();
13
14#define NITER 5
15
16static double
17Ldexp(fl,exp)
18 double fl;
19 int exp;
20{
21 extern double _fef();
22 int sign = 1;
23 int currexp;
24
25 if (fl<0) {
26 fl = -fl;
27 sign = -1;
28 }
29 fl = _fef(fl,&currexp);
30 exp += currexp;
31 if (exp > 0) {
32 while (exp>30) {
33 fl *= (double) (1L << 30);
34 exp -= 30;
35 }
36 fl *= (double) (1L << exp);
37 }
38 else {
39 while (exp<-30) {
40 fl /= (double) (1L << 30);
41 exp += 30;
42 }
43 fl /= (double) (1L << -exp);
44 }
45 return sign * fl;
46}
47
48double
49_sqt(x)
50 double x;
51{
52 extern double _fef();
53 int exponent;
54 double val;
55
56 if (x <= 0) {
57 if (x < 0) _trp(ESQT);
58 return 0;
59 }
60
61 val = _fef(x, &exponent);
62 if (exponent & 1) {
63 exponent--;
64 val *= 2;
65 }
66 val = Ldexp(val + 1.0, exponent/2 - 1);
67 /* was: val = (val + 1.0)/2.0; val = Ldexp(val, exponent/2); */
68 for (exponent = NITER - 1; exponent >= 0; exponent--) {
69 val = (val + x / val) / 2.0;
70 }
71 return val;
72}
Note: See TracBrowser for help on using the repository browser.