I am trying to write a parser in C, and part of his job is to convert a sequence of characters to double. So far I have used strtod, but I believe this is quite dangerous and it will not handle cases where the number is at the end of the buffer, which is not terminated by zero.
I thought I would write it myself. If I have a string representation of a number of the form ab, I wonβt think that I can just calculate (double) a + ((double) b / (double) 10 ^ n), where n is the number of digits in b?
For example, 23.4563:
a = 23 b = 4563
final answer: 23 + (4563/10000)
Or could this lead to inaccurate results regarding the IEEE float format?
source share