Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions PreciseNumber.Test/PreciseNumberConversionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ public void FromDecimalIsExact()
AssertFromInAllModes(0.0000000000000000000000000001m, "0.0000000000000000000000000001");
}

[TestMethod]
public void FromDecimalWithOnlyZerosAfterThePoint()
{
// Trimming the zeros of "10.0" leaves "10." with an empty fraction, which is valid text for
// ten, not a malformed rendering. This runs in Debug, where a failed assert ends the process.
Assert.AreEqual(P("10"), 10.0m.ToPreciseNumber());
Assert.AreEqual(P("100"), 100.00m.ToPreciseNumber());
Assert.AreEqual(P("-20"), (-20.0m).ToPreciseNumber());
AssertFromInAllModes(10.0m, "10");
AssertFromInAllModes(-1200.000m, "-1200");
}

[TestMethod]
public void FromBinaryFloatingPointUsesDecimalText()
{
Expand Down
2 changes: 0 additions & 2 deletions PreciseNumber/PreciseNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,6 @@
ReadOnlySpan<char> fractionalComponent = decimalIndex < 0 ? "0".AsSpan() : text[(decimalIndex + 1)..];
exponentValue -= fractionalComponent.Length;

Debug.Assert(fractionalComponent.Length != 0 || integerComponent.TrimStart("-").Length == 1, $"Unexpected format: {text}");

int digitLength = integerComponent.Length + fractionalComponent.Length;
char[]? rentedDigits = digitLength > MaxStackAllocChars ? ArrayPool<char>.Shared.Rent(digitLength) : null;
Span<char> stackDigits = stackalloc char[MaxStackAllocChars];
Expand Down Expand Up @@ -697,7 +695,7 @@
/// A fixed precision such as <c>E15</c> rounds values that need 17 digits, which turns
/// <see cref="double.MaxValue"/> into a number that converts back to infinity.
/// </remarks>
internal static string GetStringFormatForFloatType<TFloat>()

Check warning on line 698 in PreciseNumber/PreciseNumber.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this method and declare a constant for this value.

Check warning on line 698 in PreciseNumber/PreciseNumber.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this method and declare a constant for this value.

Check warning on line 698 in PreciseNumber/PreciseNumber.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this method and declare a constant for this value.

Check warning on line 698 in PreciseNumber/PreciseNumber.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this method and declare a constant for this value.

Check warning on line 698 in PreciseNumber/PreciseNumber.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this method and declare a constant for this value.

Check warning on line 698 in PreciseNumber/PreciseNumber.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Remove this method and declare a constant for this value.
where TFloat : INumber<TFloat>
=> "R";

Expand Down Expand Up @@ -1111,7 +1109,7 @@
public static PreciseNumber MinMagnitudeNumber(PreciseNumber x, PreciseNumber y) => MinMagnitude(x, y);

/// <inheritdoc/>
public static PreciseNumber Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider)

Check warning on line 1112 in PreciseNumber/PreciseNumber.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Refactor this method to reduce its Cognitive Complexity from 23 to the 15 allowed.

Check warning on line 1112 in PreciseNumber/PreciseNumber.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Refactor this method to reduce its Cognitive Complexity from 23 to the 15 allowed.

Check warning on line 1112 in PreciseNumber/PreciseNumber.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Refactor this method to reduce its Cognitive Complexity from 23 to the 15 allowed.

Check warning on line 1112 in PreciseNumber/PreciseNumber.cs

View workflow job for this annotation

GitHub Actions / Analyze & Release

Refactor this method to reduce its Cognitive Complexity from 23 to the 15 allowed.
{
if (s.IsEmpty)
{
Expand Down
Loading