Tool/software: TI C/C++ Compiler
We are seeing some unexpected behavior when using strtof and snprintf with the %f format when converting between strings and floats. We are using the ti-cgt-c2000_20.2.2.TLS library for the ARM on the CM.
strtof:
if you enter the string 15.000 it converts just fine but if you enter 15.000000000000000 you get 15.000005. When single stepping through the routine on line 170 result*base gets large and adding 0 to the value actually adds a non-zero amount. N + 0 does not equal N any longer? I think it was around when base was 1e9 or 1e10. 15.0000000000000000 only has two significant digits and is easily represented in floating point without error but the strtof does not convert without adding error for large number of zeros.
As a solution we went to using strtod to move the problem further out where it will probably not be an issue. strtod does properly convert the 15.00000000000 without error.
snprintf:
snprintf(valueStr, 23, "%.6f", msg->val.valuef);
When the float value entered is 123456790519087104 (0x5bdb4da6) the string printed is 123456790519087076.187 . This is unexpected. We tried going to %.6lf and casting the float as double but that did not resolve issue like in the strtod case.
Any thoughts on what might be causing this? It is important that the number entered is properly displayed or at least what numbers can be properly displayed and why they were not in this case.
Thanks,
Jennifer