I couldn't get my gcc-mingw to print a long double, but here's code that shows that LARGE numbers work fine with expl():
Code:
#include <math.h>
#include <stdio.h>
void printLongDouble(long double x)
{
int e = 0;
int m = 1;
int c;
int i;
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 100000.0) {
while(x > 1.0) {
e++;
x /= 10.0;
}
}
while (x < 0.00001) {
e--;
x *= 10;
}
while(m < x) m *= 10;
do {
c = (int)x / m;
putchar((char)(c+'0'));
x -= c * m;
m /= 10;
} while(x > 1.0);
if (x) {
putchar('.');
m = 1;
for(i = 0; x && i < 5; i++) {
x *= 10;
c = (int)x % 10;
putchar((char)(c + '0'));
}
}
if (e)
{
if (e >= 0) c = '+';
else {
c = '-';
e = -e;
}
printf("E%c%d",c, e);
}
putchar('\n');
}
int main() {
long double ld;
double d;
for(;;) {
scanf("%lf", &d);
ld = d;
printLongDouble(expl(ld));
}
return 0;
}
Execution sample:
Code:
D:\temp>gcc -Wall exp.c
D:\temp>a
1000
0.19700E+435
9000
0.44703E+3909
--
Mats