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

bugfix in Rational.cs, when both Nominator and Denominator equals to 0 #2453

Merged
merged 6 commits into from
Jun 12, 2023

Conversation

tsardaryanCamenAI
Copy link
Contributor

@tsardaryanCamenAI tsardaryanCamenAI commented May 11, 2023

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

In cases, when you're trying to create Rational.FromDouble(0) it generates an invalid Rational item.

@CLAassistant
Copy link

CLAassistant commented May 11, 2023

CLA assistant check
All committers have signed the CLA.

@@ -74,6 +74,11 @@ public Rational(double value, bool bestPrecision)

this.Numerator = (uint)rational.Numerator;
this.Denominator = (uint)rational.Denominator;

if(this.Numerator == 0 && this.Denominator == 0)
Copy link
Member

Choose a reason for hiding this comment

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

If there's an issue here it will have to be fixed in LongRational

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if you want to update GPS location of ExifInformation, it accepts Retional[]. That's why I suggest this change. Anyway if you are creating Rational.FromDouble(0) Denominator shouldn't be 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, you're right, the problem is deeper on line 206 of LongRational.cs it should be

return new LongRational(0, 1);

Copy link
Member

Choose a reason for hiding this comment

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

That's the correct fix. Can you also add some unit tests for this to make sure this stays fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, sure will do that and will push all as a different pull request. You can close this one.

Copy link
Member

Choose a reason for hiding this comment

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

No need to open a new PR. That’s just confusing. Push to this one please.

Copy link
Member

Choose a reason for hiding this comment

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

And you can also use a force push to update this PR with a new set of commits.

@@ -153,6 +153,10 @@ public static LongRational FromDouble(double value, bool bestPrecision)
double df = numerator / (double)denominator;
double epsilon = bestPrecision ? double.Epsilon : .000001;

if(val < epsilon) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the fix be the following inserted at 149?

if (value == 0)
{
    return new LongRational(0, 1);
}

@JimBobSquarePants JimBobSquarePants added this to the v3.1.0 milestone May 19, 2023
@JimBobSquarePants JimBobSquarePants merged commit f5e4605 into SixLabors:main Jun 12, 2023
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