Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_fixcpp/sys/src/ape/lib/ap/stdio/pow10.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <errno.h>
2
#include <float.h>
3
#include <math.h>
4
 
5
static	long	tab[] =
6
{
7
	1L, 10L, 100L, 1000L, 10000L,
8
	100000L, 1000000L, 10000000L
9
};
10
 
11
double
12
pow10(int n)
13
{
14
	int m;
15
 
16
	if(n > DBL_MAX_10_EXP){
17
		errno = ERANGE;
18
		return HUGE_VAL;
19
	}
20
	if(n < DBL_MIN_10_EXP){
21
		errno = ERANGE;
22
		return 0.0;
23
	}
24
	if(n < 0)
25
		return 1/pow10(-n);
26
	if(n < sizeof(tab)/sizeof(tab[0]))
27
		return tab[n];
28
	m = n/2;
29
	return pow10(m) * pow10(n-m);
30
}