C
Christian Meier
Hallo NG
My problem is the deviation of the floating point datatypes. 90.625 is not
exactly 90.625. It is 90.624999999.... on my system. Now I tried to find a
solution for my problem but I couldn't think of one. So I tried to write a
work-arround which should solve the problem for the most numbers.
What do you think of this: (I know it is not a perfect solution....)
double dValue = ...;
if (dValue >= 10000000000000LL) {
nInValue += 0.01;
} else if (dValue >= 1000000000000LL) {
nInValue += 0.001;
} else if (dValue >= 100000000000LL) {
nInValue += 0.0001;
} else if (dValue >= 10000000000LL) {
nInValue += 0.00001;
} else if (dValue >= 1000000000) {
nInValue += 0.000001;
} else if (dValue >= 100000000) {
nInValue += 0.0000001;
} else if (dValue >= 10000000) {
nInValue += 0.00000001;
} else if (dValue >= 1000000) {
nInValue += 0.000000001;
} else if (dValue >= 100000) {
nInValue += 0.0000000001;
} else if (dValue >= 10000) {
nInValue += 0.00000000001;
} else if (dValue >= 1000) {
nInValue += 0.000000000001;
} else if (dValue >= 100) {
nInValue += 0.0000000000001;
} else if (dValue >= 10) {
nInValue += 0.00000000000001;
} else if (dValue < 0) {
nInValue -= 0.000000000000001;
} // if
Greets Chris
My problem is the deviation of the floating point datatypes. 90.625 is not
exactly 90.625. It is 90.624999999.... on my system. Now I tried to find a
solution for my problem but I couldn't think of one. So I tried to write a
work-arround which should solve the problem for the most numbers.
What do you think of this: (I know it is not a perfect solution....)
double dValue = ...;
if (dValue >= 10000000000000LL) {
nInValue += 0.01;
} else if (dValue >= 1000000000000LL) {
nInValue += 0.001;
} else if (dValue >= 100000000000LL) {
nInValue += 0.0001;
} else if (dValue >= 10000000000LL) {
nInValue += 0.00001;
} else if (dValue >= 1000000000) {
nInValue += 0.000001;
} else if (dValue >= 100000000) {
nInValue += 0.0000001;
} else if (dValue >= 10000000) {
nInValue += 0.00000001;
} else if (dValue >= 1000000) {
nInValue += 0.000000001;
} else if (dValue >= 100000) {
nInValue += 0.0000000001;
} else if (dValue >= 10000) {
nInValue += 0.00000000001;
} else if (dValue >= 1000) {
nInValue += 0.000000000001;
} else if (dValue >= 100) {
nInValue += 0.0000000000001;
} else if (dValue >= 10) {
nInValue += 0.00000000000001;
} else if (dValue < 0) {
nInValue -= 0.000000000000001;
} // if
Greets Chris