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

Odd integer division rounding behavior #223

Open
sfrezza opened this issue Jul 23, 2024 · 3 comments
Open

Odd integer division rounding behavior #223

sfrezza opened this issue Jul 23, 2024 · 3 comments
Labels
question Further information is requested

Comments

@sfrezza
Copy link

sfrezza commented Jul 23, 2024

I had to do odd work-arounds to get integer division to behave normally.

When $totalValue is 1, these two formulations do not compute the same result (I think they should both be zero). See the following DoenetML code snippet:

1
($totalValue)/2
vs.
($totalValue-0.1)/2

In the first case, $quo0 is set to 1; in the second $quo1 is set to 0. Shouldn't they both compute zero?

In normal rounding or truncation, if the dividend from 1/2 = 0.50 or less, then the integer conversion of this result should be zero. Why in the first case is it 1?

@dqnykamp
Copy link
Member

That's fascinating. In your domain, the convention is round 0.5 down to zero? I think it is arbitrary, but I'm more familiar with the convention of rounding 0.5 up to 1!

For the Doenet component <round>, we could always add an attribute to specify the behavior of rounding 0.5. But, for the math function round(x), I can't think of a way to make it flexible, as it would be a strange approach to add an extra argument to determine this behavior.

@sfrezza
Copy link
Author

sfrezza commented Jul 24, 2024 via email

@dqnykamp
Copy link
Member

Doenet definitely started with a focus on math, so I didn't consult IEEE standards.

Just looked up IEEE 754. If one implements roundTiesToEven, then 0.5 should be rounded to 0. If one implements roundTiesToAway, then 0.5 should be rounded to 1.

It looks like for decimal formats, the default is language defined, but they recommend roundTiesToEven. (For binary formats, they require roundTiesToEven.) From section 4.3.3:

The roundTiesToEven rounding-direction attribute shall be the default rounding-direction attribute for
results in binary formats. The default rounding-direction attribute for results in decimal formats is
language-defined, but should be roundTiesToEven.

I feel like I should consult with additional stakeholders to know how to proceed. If math folks don't have strong opinions, then it would make sense to follow the IEEE recommendations.

@dqnykamp dqnykamp added the question Further information is requested label Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants