-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce rounding #255
Introduce rounding #255
Conversation
Whoa, cool, thanks for the patch! I'll study it today sometime, but at first glance it seems reasonable. Could I ask you for some unit tests that confirm the behavior works as expected please? Additionally, if you're interested, feel free to add yourself to the contributors file! |
BTW I think I just set up nanoprintf to automatically run the PR actions for all contributors, so hopefully I won't need to manually click "yes yes please run the actions" every time you push. |
/tests/unit_ftoa_rev.cc : /tests/mpaland-conformance/paland.cc:592 : While developing I just tested these cases manually:
I'll look into how to add those as an additional unit tests. By the way, for analyzing floating point values and limits, I used this tool: |
Re:
I don't yet understand why those would round up, is that intentional? |
I can handle the paland stuff if you like, it's not set up for collaborative development- i just push directly to main over there once a local branch works against the PR i have open in this repo... |
Reviewed all of the float related tests in the paland.cc file and readjusted the expected values for the affected ones.
Those are not rounded but just truncated at the limit of the precision. The actual single float values stored are:
Because of Thinking more about the limits... Mathematically the resolution of the 32-bit float is The actual float value: 42.89522552490234375 I guess that's the mathematically right way... Should I go forward and readjust for 9 digits? |
I applied your patch over on the mpaland-conformance branch, and pushed it to a remote with the name Thanks for the explanation about 1/3 etc. I think it makes sense to have the max fraction decimal digits to equal 9 as well, your reasoning seems right to me... Also, thanks for all of the work on this patch! |
I just merged your changes to the mpaland-conformance branch; they're now in main! One last change, just bumping the submodule SHA to main and we're good to merge! |
I'll go through the test cases and create a patch for 9 digit version. If that doesn't create unexpected issues, I guess we should add it to this PR? |
Sure, sounds good to me. |
There it is: rounding9.patch |
Applied and pushed your rounding9 patch to a |
Looks good, I'll merge the mpaland PR and then you can bump this (again), and then .... merge? |
mpaland is merged, you can bump the sha to main whenever you like. |
This looks good to me, is there anything else you want to get into this PR or shall I merge it? Thanks again for the contribution! |
It seems that this PR is complete. Now looking at the code I have some ideas for a potential improvement for both precision and rounding, but at this point those are just rough ideas. In short - the Thanks to you also for a nice printf library implementation! As the Newlib implementation is unusable, I looked for alternatives for some MCU projects. For a device based on STM32L432 I chose this one, because it is compact and supports float values. But, as I need a proper rounding in that project, I looked if I can implement it myself. |
Thanks for the kind words! I would be very interested in such a PR if you felt motivated. The floating-point portion of nanoprintf is definitely the weakest part of it, in my opinion. It feels like there are many size optimizations lurking there, as you mention. |
The impact on footprint and performance is tiny and the code turned out to be relatively simple. In my opinion a mathematical correctness is definitely worth for such a minor sacrifice.