1: /* @(#)sqrt.c 4.1 12/25/82 */
2:
3: /*
4: sqrt returns the square root of its floating
5: point argument. Newton's method.
6:
7: calls frexp
8: */
9:
10: #include <errno.h>
11:
12: int errno;
13: double frexp();
14:
15: double
16: sqrt(arg)
17: double arg;
18: {
19: double x, temp;
20: int exp;
21: int i;
22:
23: if(arg <= 0.) {
24: if(arg < 0.)
25: errno = EDOM;
26: return(0.);
27: }
28: x = frexp(arg,&exp);
29: while(x < 0.5) {
30: x *= 2;
31: exp--;
32: }
33: /*
34: * NOTE
35: * this wont work on 1's comp
36: */
37: if(exp & 1) {
38: x *= 2;
39: exp--;
40: }
41: temp = 0.5*(1.0+x);
42:
43: while(exp > 60) {
44: temp *= (1L<<30);
45: exp -= 60;
46: }
47: while(exp < -60) {
48: temp /= (1L<<30);
49: exp += 60;
50: }
51: if(exp >= 0)
52: temp *= 1L << (exp/2);
53: else
54: temp /= 1L << (-exp/2);
55: for(i=0; i<=4; i++)
56: temp = 0.5*(temp + arg/temp);
57: return(temp);
58: }
Defined functions
sqrt
defined in line
15; used 88 times
- in /usr/include/math.h line
10
- in /usr/ingres/source/ovqp/interp.c line
30,
442
- in /usr/src/games/phantasia/fight.c line
369
- in /usr/src/games/phantasia/func0.c line
627
- in /usr/src/games/phantasia/main.c line
308(2)
- in /usr/src/games/phantasia/phant.h line
27
- in /usr/src/games/primes.c line
101
- in /usr/src/games/snake/snake.c line
569-571(2)
- in /usr/src/games/trek/compkl.c line
39
- in /usr/src/games/trek/computer.c line
306
- in /usr/src/games/trek/help.c line
67
- in /usr/src/games/trek/move.c line
193
- in /usr/src/games/trek/trek.h line
30
- in /usr/src/include/math.h line
10
- in /usr/src/new/OLD/apl/src/a8.c line
129
- in /usr/src/new/OLD/apl/src/ao.c line
155,
161,
180,
188,
259
- in /usr/src/new/OLD/apl/src/apl.h line
452
- in /usr/src/new/PORT/apl/src/a8.c line
129
- in /usr/src/new/PORT/apl/src/ao.c line
155,
161,
180,
188,
259
- in /usr/src/new/PORT/apl/src/apl.h line
452
- in /usr/src/new/PORT/perl.1.0.0/arg.c line
1201,
1925
- in /usr/src/new/PORT/perl.1.0.0/perly.c line
1834,
2013
- in /usr/src/new/PORT/perl.1.0.10/arg.c line
1229,
1953
- in /usr/src/new/PORT/perl.1.0.10/perly.c line
1868,
2047
- in /usr/src/new/PORT/perl.1.0.16/arg.c line
1248,
1977
- in /usr/src/new/PORT/perl.1.0.16/perly.c line
1869,
2048
- in /usr/src/ucb/PORT/pascal/px/interp.c line
1674
- in /usr/src/ucb/pascal/px/00int.s line
8
- in /usr/src/ucb/pascal/px/34fun.s line
148
- in /usr/src/usr.bin/plot/crtplot.c line
233,
249
- in /usr/src/usr.lib/libF77/c_sqrt.c line
14,
20-25(2)
- in /usr/src/usr.lib/libF77/r_sqrt.c line
12-13(2)
- in /usr/src/usr.lib/libF77/z_sqrt.c line
14,
20-25(2)
- in /usr/src/usr.lib/libom/asin.c line
13,
32
- in /usr/src/usr.lib/libom/hypot.c line
8,
27
- in /usr/src/usr.lib/libom/j0.c line
133,
140,
153,
164
- in /usr/src/usr.lib/libom/j1.c line
135,
143,
158,
170
- in /usr/src/usr.lib/libplot/bitgraph/arc.c line
36,
54
- in /usr/src/usr.lib/libplot/imagen/arc.c line
17,
25,
53,
81
- in /usr/src/usr.lib/libplot/t300/line.c line
18-20(2)
- in /usr/src/usr.lib/libplot/t300s/line.c line
18-20(2)
- in /usr/src/usr.lib/libplot/t4013/arc.c line
17,
25,
53,
81
- in /usr/src/usr.lib/libplot/t4014/arc.c line
11,
19,
47,
75
- in /usr/src/usr.lib/libplot/t450/line.c line
18-20(2)
Defined variables
errno
defined in line
12; used 1 times