How do I implement strtod?

596 Views Asked by At

For example lets take the value 10.23E-4. What I did was break it up into several variables, whole=10, decimal=23, decimalLength=2, isNegative=1, exponent=4 (is there a better name for these?)

First I d = decimal; d*/exp10(decimalLength); d+=whole;. This gets me 10.23. Next I wrote e = exp10(exponent); if (isNegative) e = 1/e; result = d*e;. I suspect this part is wrong. My result is 0.0010229999999999998 while strtod is 0.001023. What's the proper way to handle the exponent? Is there a good+fast implementation of strtod I can compare my code to?

0

There are 0 best solutions below