S
Steven
Hi,
I am trying to find out how many digits there are in a given number.
The macro listed below works fine when applied to an INT, however when
doing Doubles with numbers > then a billion ?? It stops working.
Anyone any idea's ?
Thankx !
Steven.
#include <stdio.h>
#include <math.h>
#define DIGLEN(x) (x ? (int)(log10((double)(abs(x)))) + 1 : 1)
int main(int argc, char *argv[]) {
int i = 123;
double j = 807319385.29;
double k = 12258983401.75;
printf("%3d: %d\n", DIGLEN(i), i);
printf("%3d: %.2f\n", DIGLEN(j), j);
printf("%3d: %.2f\n", DIGLEN(k), k);
return 0;
}
I am trying to find out how many digits there are in a given number.
The macro listed below works fine when applied to an INT, however when
doing Doubles with numbers > then a billion ?? It stops working.
Anyone any idea's ?
Thankx !
Steven.
#include <stdio.h>
#include <math.h>
#define DIGLEN(x) (x ? (int)(log10((double)(abs(x)))) + 1 : 1)
int main(int argc, char *argv[]) {
int i = 123;
double j = 807319385.29;
double k = 12258983401.75;
printf("%3d: %d\n", DIGLEN(i), i);
printf("%3d: %.2f\n", DIGLEN(j), j);
printf("%3d: %.2f\n", DIGLEN(k), k);
return 0;
}