Skip to content
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

utils: fix rounding functions #38

Merged
merged 1 commit into from
Apr 9, 2018
Merged

Conversation

yerden
Copy link
Contributor

@yerden yerden commented Apr 8, 2018

Standard MathMod() function may return not-so-correct results
so it cannot be relied upon when rounding. For example,
MathMod(0.6,0.1) yields 0.099999.. which may be deceiving.
This caveat makes rounding completely incorrect with current
logic. Use MathRound() instead.

Changes:

  • modify roundUpToMultiple/roundDownToMultiple to use MathRound();
  • add roundUpToStep/roundDownToStep functions calculating value
    with regard to a minimum value and a step.

New functions are useful to calculate correct lots with
SYMBOL_VOLUME_MIN/SYMBOL_VOLUME_STEP.

Big diff is MetaEditor Styler's fault, not mine 😄

Standard MathMod() function may return not-so-correct results
so it cannot be relied upon when rounding. For example,
MathMod(0.6,0.1) yields 0.099999.. which may be deceiving.
This caveat makes rounding completely incorrect with current
logic. Use MathRound() instead.

Changes:
* modify roundUpToMultiple/roundDownToMultiple to use MathRound();
* add roundUpToStep/roundDownToStep functions calculating value
  with regard to a minimum value and a step.

New functions are useful to calculate correct lots with
SYMBOL_VOLUME_MIN/SYMBOL_VOLUME_STEP.

Signed-off-by: Yerden Zhumabekov <[email protected]>
Copy link
Owner

@dingmaotu dingmaotu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would never thought that MathMod could be inaccurate sometimes. I need to verify this when I have time but these additions are really helpful. So I will merge them first, haha.

@dingmaotu dingmaotu merged commit 0d20d72 into dingmaotu:master Apr 9, 2018
@yerden
Copy link
Contributor Author

yerden commented Apr 10, 2018

Floating point computations are not so straightforward due to hardware limitations. This is really a thing to keep an eye on.

@yerden yerden deleted the math_fix branch April 10, 2018 05:04
@yerden yerden restored the math_fix branch April 4, 2019 15:10
@yerden yerden deleted the math_fix branch April 4, 2019 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants