Skip to content

Length.Zero.Inverse() returns ReciprocalLength.Zero (v6) #1535

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

Closed
lipchev opened this issue Apr 11, 2025 · 2 comments · Fixed by #1540
Closed

Length.Zero.Inverse() returns ReciprocalLength.Zero (v6) #1535

lipchev opened this issue Apr 11, 2025 · 2 comments · Fixed by #1540
Labels

Comments

@lipchev
Copy link
Collaborator

lipchev commented Apr 11, 2025

Since the release/v6 supports NaN and PositiveInfinity I think it would make sense for:

        [Theory]
        [InlineData(-1.0, -1.0)]
        [InlineData(-2.0, -0.5)]
        [InlineData(0.0, 0.0)]
        [InlineData(1.0, 1.0)]
        [InlineData(2.0, 0.5)]
        public static void InverseReturnsReciprocalLength(double value, double expected)
        {
            var length = new Length(value, LengthUnit.Meter);
            var inverseLength = length.Inverse();

            Assert.Equal(expected, inverseLength.InverseMeters);
        }

to be changed to:

        [Theory]
        [InlineData(-1.0, -1.0)]
        [InlineData(-2.0, -0.5)]
        [InlineData(0.0, double.PositiveInfinity)]
        [InlineData(1.0, 1.0)]
        [InlineData(2.0, 0.5)]
        public static void InverseReturnsReciprocalLength(double value, double expected)
        {
            var length = new Length(value, LengthUnit.Meter);
            var inverseLength = length.Inverse();

            Assert.Equal(expected, inverseLength.InverseMeters);
        }
@lipchev lipchev added the bug label Apr 11, 2025
@angularsen
Copy link
Owner

angularsen commented Apr 11, 2025

Sounds good, as long as we're all in on double now. We'll just have to revisit if and when we introduce other number types again.

@lipchev
Copy link
Collaborator Author

lipchev commented Apr 11, 2025

Sounds good, as long as we're all in on double now. We'll just have to revisit if and when we introduce other number types again.

Here's how I currently represent these:

    /// <summary>
    ///     The value representing the positive infinity.
    /// </summary>
    public static QuantityValue PositiveInfinity { get; } = new(BigInteger.One, BigInteger.Zero);

    /// <summary>
    ///     The value representing the negative infinity.
    /// </summary>
    public static QuantityValue NegativeInfinity { get; } = new(BigInteger.MinusOne, BigInteger.Zero);

    /// <summary>
    ///     The value representing the result of dividing zero by zero.
    /// </summary>
    public static QuantityValue NaN { get; } = new(BigInteger.Zero, BigInteger.Zero);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants