aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/map/libmap/cubrt.c
blob: fd508d2baae56d34302020f5099bc4901aee0a64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <u.h>
#include <libc.h>
#include "map.h"

double
cubrt(double a)
{
	double x,y,x1;
	if(a==0) 
		return(0.);
	y = 1;
	if(a<0) {
		y = -y;
		a = -a;
	}
	while(a<1) {
		a *= 8;
		y /= 2;
	}
	while(a>1) {
		a /= 8;
		y *= 2;
	}
	x = 1;
	do {
		x1 = x;
		x = (2*x1+a/(x1*x1))/3;
	} while(fabs(x-x1)>10.e-15);
	return(x*y);
}