Skip to content

Commit 9c4fb8e

Browse files
Make a whole number the rational search finds an integer (#2071)
The continued fraction built its result with new Rational(...), past the check in Rational.Create that turns a denominator of one into an Integer, so a decimal just below a whole number came back as the Rational 1/1 or 3/1: not an Integer, and not equal to 1 or 3. Fixes #2069. Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 1c1c506 commit 9c4fb8e

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ solver's check that a limit agrees from both sides goes through the same compari
126126
| `AreEqualNumerically("2 x (-1/4 + ln(x)/2) + 1/x * 2/4 * x^2", "x ln(x)")` | `false` | `true` |
127127
| `AreEqualNumerically` of `x ln(x)` and its antiderivative's derivative | `false` | `true` |
128128

129+
### A whole number the rational search finds is an integer
130+
131+
**Silent: a wrong type and a wrong comparison.** The search that reads a number as the rational it is near built its
132+
result without the check that turns a denominator of 1 into an integer. A value just below a whole number came back as
133+
the `Rational` `1/1` or `3/1`, which is not an `Integer` and is not equal to `1` or `3`
134+
([#2069](https://github.com/asc-community/AngouriMath/issues/2069)).
135+
136+
| Input | Was (2.6.0) | Now |
137+
|---|---|---|
138+
| `(Entity)0.9999999999999999999999999999m` | `Rational 1/1`, and `== 1` is `false` | `Integer 1` |
139+
| `(Entity)2.9999999999999999999999999999m` | `Rational 3/1` | `Integer 3` |
140+
129141
### A computed value is a rational only within half the working digits
130142

131143
**Silent: wrong answers.** A number an evaluation produced became the small rational it was near within a fixed

‎Sources/AngouriMath/Core/Entity/Continuous/Entity.Continuous.Rational.Definition.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ public static Rational Create(ERational value)
215215
var rat = FindRationalExactly(inv, iterCount - 1, tolerance);
216216
if (rat is null)
217217
return null;
218-
return new Rational((intPart * sign + sign / rat.ERational).InLowestTerms());
218+
// Through Create, so that a whole number is an Integer: a value just below one is 0 + 1/1, and
219+
// came back as the Rational 1/1, which is not equal to 1.
220+
// https://github.com/asc-community/AngouriMath/issues/2069
221+
return Rational.Create(intPart * sign + sign / rat.ERational);
219222
}
220223
}
221224

‎Sources/Tests/UnitTests/Core/NumericDowncasting.cs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,5 +270,20 @@ [Fact] public void FromRationalTestRealDowncastingEnabledInt()
270270
);
271271

272272
#endregion
273+
274+
/// <summary>
275+
/// A whole number the rational search finds is an <see cref="Integer"/>: a value just below one came back
276+
/// as the Rational 1/1, which is not equal to 1.
277+
/// <a href="https://github.com/asc-community/AngouriMath/issues/2069">#2069</a>
278+
/// </summary>
279+
[Theory]
280+
[InlineData("0.9999999999999999999999999999", 1)]
281+
[InlineData("2.9999999999999999999999999999", 3)]
282+
public void AWholeNumberFromTheRationalSearchIsAnInteger(string written, int whole)
283+
{
284+
Entity value = decimal.Parse(written, System.Globalization.CultureInfo.InvariantCulture);
285+
value.Should().BeOfType<Integer>();
286+
value.Should().Be((Entity)whole);
287+
}
273288
}
274-
}
289+
}

0 commit comments

Comments
 (0)