@westfw thank you, I used the tip you gave me for __ftoa_engine. It was a new concept and I read about in here (http://www.geeksforgeeks.org/extern-c-in-c/). Thank you again, without your guidance I would never learn that.
@krupski, sorry to let you down. I did not mean to. Anyways later if I release the libraries which I am working on right now, I think more people will be benefited if no tweaks are needed on the IDE side. Again I am sorry if I have made you upset.
Things I have done which might be useful for future users:
- I documented the dtoa_prf function which is the actual function when dtostrf is called. The code does not have any documentation and I think it has been implemented in a very smart and efficient way and without documentation it is hard to understand it.
- I made a safe version and tried to test it as much as I could in few aspects.
i) dtosrf and myDtostrf produce the same exact results when size is not an issue. (it was tested for hours by generating random float numbers)
ii) NAN, INF, -INF are tested with different sizes to make sure correct result is obtained
iii) size was tested on some variables (I have not seen any suspicious behavior but I think more testing is required which hopefully happens over time when I am testing other parts of the project)
- finding out that another person has faced the same issue but the whole thread is in german
My overall code is in here (well, it was too long so had to attach it)
myDtoa_prf part of this code is exactly same as dtoa_prf and buy reading the comments you can easily understand the original dtoa_prf too.
There is only one part which I did not understand and that is
if ((signed char)nDigits < 1)
nDigits = 1;
else if (nDigits > 8)
nDigits = 8;
I tested with
if ((signed char)nDigits < 0)
nDigits = 1;
else if (nDigits > 8)
nDigits = 8;
and it produce exact same results after testing with random float number, but I think it is faster because it can be branch if minus. (I am not very familiar with AVR assembly instruction yet but from what I recall from 6800 instruction set, branch if minus was faster than comparing and then branching)
I would be happy if anyone can point out why there is a 1 there instead of 0. I am afraid it is for a very special case and the random number generator has not generated that.
The code I have attached contain the testing section. Let me know if you think the testing part is not accurate, I think it is fairly accurate but just to be sure.
And lastly,
https://www.mikrocontroller.net/topic/301125
shows folks who solved the same problem. However my version has one difference. Their version does not print the number at all if it does not fit. My version it prints as much as it can and then set the bool argument which passed by reference to false.
I would like to thank you all for the support, suggestions and your efforts.
floatEngineTest.ino (22.2 KB)