8000 FloatCounter test and possible corrections by melvilpf · Pull Request #7535 · libgdx/libgdx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

FloatCounter test and possible corrections #7535

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

melvilpf
Copy link
Contributor

I have worked on the com.badlogic.gdx.math FloatCounter class. I just wanted to add some tests to find out the limits of the counter and I am thus suggesting a few modifications to the class to avoid big errors with the large numbers (I think this could be interesting, since this class isn't meant for such usages, to prevent them from happening).

Copy link
Contributor
@Frosty-J Frosty-J left a comment

Choose a reason for hiding this comment

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

Interesting observations.

*
* else if (Float.isInfinite(value)) throw new RuntimeException("value is infinite"); else if
* (value==Float.MAX_VALUE||value==-Float.MAX_VALUE) throw new RuntimeException("value is too big and " +
* "there are risks that the next results will be different than expected");
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not like the idea of throwing an exception for crazy values. Someone might want to do that, or there might be some scenario where a game ends up at MAX_VALUE and now it'll crash (which is worse than just behaving incorrectly).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should i keep the NaN exception though ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or maybe I should avoid having both POSITIVE_INFINITY and - NEGATIVE_INFINITY ? that's the issue I tested where the total was then NaN

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't throw an exception over putting a NaN value for much the same reason. Maybe we should return early on NaN to avoid screwing up the total/average. I'd be interested to hear what someone else thinks.

Infinities and other extreme values will always cause problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so like adding the NaN to the values but not to the total or average then ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't inspected it but I reckon NaN would break WindowedMean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey so should I keep FloatCounter as it is and rewrite the tests for it to take into account NaN etc ?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to. I'm still not that sure on any of this; would like to see if someone who actually uses FloatCounter has thoughts on the matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, I can still wait for someone to confirm how it works

Copy link
Member

Choose a reason for hiding this comment

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

Imagine if we checked for odd float values for every method that accepted floats -- it isn't reasonable to guard against unless there are some special requirements.

counter1.put(7E18f);
Assert.assertEquals(1750000000000002519.00000000000000000000000000000000000002938735875f, counter1.average, 0);
counter1.put(5f);
Assert.assertEquals(1400000000000002013.80000000000000000000000000000000000002350988700f, counter1.mean.getMean(), 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like you've hardcoded values that will pass the test. Consider using MathUtils#isEqual.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, will do !

counter2.put(Float.NEGATIVE_INFINITY);
/*
* After implementing this next test, I realized that putting POSITIVE_INFINITY then NEGATIVE_INFINITY, the total was not a
* number (same as before, should this be prohibited ?)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider marking your pull request as draft if it contains questions, since this doesn't look ready to be merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also done thank you

@melvilpf melvilpf marked this pull request as draft November 28, 2024 14:06
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.

4 participants
0