@guest3456:
What you're effectively doing is:
MsgBox, % Ceil(222.00000000000002) ;223
And insisting that it should be 222.
I.e. your function rounds before ceiling, which can be a good thing, but by what criteria.
Ideally the logic for this should be fully explained (commented).
In short, floating-point numbers are complicated, and I'd want a more rigorous analysis of the situation, than this, that gives no real justification for the general case, and cites only one example:
PHP Rounding Numbers - Stack Overflow
https://stackoverflow.com/questions/2074527/php-rounding-numbers/48933199#48933199
I wrote a barebones function with the core logic.
To improve it, two considerations are:
- Avoiding using Round or Format, and treating everything as strings, such that the function is completely WYSIWYG, with no black boxes, and consistent in any programming language. This immediately leads to writing a complete maths via strings library.
- Rounding before ceiling/flooring. Perhaps discussing with others a default accuracy to chop to, and possibly adding a parameter to specify this.
Any other considerations would be interesting to hear. *That's why I asked for feedback in my original thread.*
That said, I'd recommend as the best solution, re. accuracy and performance, to store numbers as integers and format them as decimals for presentation.
(Btw there's no need for this: 'clearly illogical', 'remind me not to use your code', 'don't take offense', 'your code is wrong, just admit it'.)
@Helgef:
I've addressed improving the function above.
Over time, the benefits of having a complete understanding of how the AHK built-in functions handle floating-point numbers, has become apparent. E.g. it would help explain the 'consistent results' issue you mentioned.
From experience, you/others are unlikely to want to write a report on that, but it would be most welcome.
A good start would be if you or someone else would explain the Round/Format discrepancies:
Rounding error - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=69908
Also, do you have the link for that GitHub discussion, it may have been re. exponentiation. Thanks.
[EDIT:] Perhaps it was this:
Changing operator ** to not cast integer operands to float... by HelgeffegleH · Pull Request #119 · Lexikos/AutoHotkey_L · GitHub
https://github.com/Lexikos/AutoHotkey_L/pull/119
Link:
jeeswg's floats and doubles mini-tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=74&t=63650