printf icon indicating copy to clipboard operation
printf copied to clipboard

Float enhancements

Open essele opened this issue 4 years ago • 1 comments

Hi,

I'm very impressed with your printf implementation .. I've been using it on an embedded project with a great improvement in memory usage.

However, I've recently just added eLua to the project and it uses "%.14g" as it's printed number representation and I noticed that there were quite a few issues with %g and %e support, as well as the 9 digit precision limitation.

Anyway, I've forked it and created a few enhancements to the overall float support, the main changes are:

  • support for 18 digit precision
  • proper trailing zero handling for %g
  • removal of all the bit manipulation (mostly because I don't understand it)
  • supports all the bizarre interactions caused by HASH
  • moved zero padding into the _out_rev2 routine (should replace other uses really)

It passes all the tests apart from two ... one that you have wrong (%0-15.3g) which actually shouldn't have any digits after the decimal place, and the one that checks for 9 digits of precision, since there is now 18.

I've run the tests on a 32bit and 64bit system and the behaviour is the same.

It should be similar in terms of memory consumption and performance, but I haven't run any detailed tests yet.

I do still need to fully replace the out_rev function with out_rev2, I'll work on that next, but thought it would be useful to create a pull request.

Hope this is useful -- very happy to receive any feedback you might have!

Lee.

essele avatar Feb 26 '21 15:02 essele

It's a bit difficult to figure out what change regards what issue. And - the commits don't really correspond to the issues, and involve adding and removing code that eventually isn't used. I'd try to clean up the commit history, and quite possibly break up the PR into several smaller PRs (or even - incremental ones).

eyalroz avatar Jun 30 '21 07:06 eyalroz