< Summary

Information
Class: FixedMathSharp.Signed192
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Wide/Signed192.cs
Line coverage
100%
Covered lines: 30
Uncovered lines: 0
Coverable lines: 30
Total lines: 94
Line coverage: 100%
Branch coverage
100%
Covered branches: 26
Total branches: 26
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_One()100%11100%
.ctor(...)100%11100%
get_IsZero()100%11100%
get_Sign()100%44100%
Raw(...)100%11100%
Signed(...)100%22100%
NarrowValue(...)100%11100%
TryNarrowSigned(...)100%66100%
NarrowProven(...)100%11100%
NarrowValue(...)100%11100%
TryNarrowSigned(...)100%1414100%
Equals(...)100%11100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Wide/Signed192.cs

#LineLine coverage
 1//=======================================================================
 2// Signed192.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024–present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using System.Runtime.CompilerServices;
 9
 10namespace FixedMathSharp;
 11
 12/// <summary>
 13/// A signed two's-complement value wide enough for sums of full-domain
 14/// Q32.32 endpoint-difference products.
 15/// </summary>
 16internal readonly struct Signed192
 17{
 16048918    public static Signed192 One => Signed(Fixed64.One.m_rawValue);
 19
 20    internal readonly ulong High;
 21    internal readonly ulong Middle;
 22    internal readonly ulong Low;
 23
 24    internal Signed192(ulong high, ulong middle, ulong low)
 25    {
 966923226        High = high;
 966923227        Middle = middle;
 966923228        Low = low;
 966923229    }
 30
 2075730231    internal bool IsZero => (High | Middle | Low) == 0UL;
 32
 2070304133    internal int Sign => IsZero ? 0 : (High & (1UL << 63)) != 0UL ? -1 : 1;
 34
 191741735    internal static Signed192 Raw(Fixed64 value) => Signed(value.m_rawValue);
 36
 37    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 38    internal static Signed192 Signed(long value)
 39    {
 262157440        ulong extension = value < 0L ? ulong.MaxValue : 0UL;
 262157441        return new Signed192(extension, extension, unchecked((ulong)value));
 42    }
 43
 44    /// <summary>
 45    /// Narrows a five-word signed value to a three-word signed value, discarding the two most significant words.
 46    /// </summary>
 30717847    internal static Signed192 NarrowValue(Signed320 value) => new(value.Word2, value.Word1, value.Word0);
 48
 49    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 50    internal static bool TryNarrowSigned(Signed320 value, out Signed192 result)
 51    {
 306492252        ulong extension = (value.Word2 & (1UL << 63)) != 0UL ? ulong.MaxValue : 0UL;
 306492253        if (value.Word4 != extension || value.Word3 != extension)
 54        {
 49576955            result = default;
 49576956            return false;
 57        }
 58
 256915359        result = new Signed192(value.Word2, value.Word1, value.Word0);
 256915360        return true;
 61    }
 62
 63    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 64    internal static Signed192 NarrowProven(Signed320 value)
 65    {
 2528766        _ = TryNarrowSigned(value, out Signed192 result);
 2528767        return result;
 68    }
 69
 70    /// <summary>
 71    /// Narrow a Signed576 value to a Signed192 value, discarding the upper 384 bits.
 72    /// </summary>
 2773    internal static Signed192 NarrowValue(Signed576 value) => new(value.Word2, value.Word1, value.Word0);
 74
 75    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 76    internal static bool TryNarrowSigned(Signed576 value, out Signed192 result)
 77    {
 117134478        ulong extension = (value.Word2 & (1UL << 63)) != 0UL ? ulong.MaxValue : 0UL;
 117134479        if (value.Word8 != extension || value.Word7 != extension || value.Word6 != extension
 117134480            || value.Word5 != extension || value.Word4 != extension || value.Word3 != extension)
 81        {
 40771882            result = default;
 40771883            return false;
 84        }
 85
 76362686        result = new Signed192(value.Word2, value.Word1, value.Word0);
 76362687        return true;
 88    }
 89
 90    internal bool Equals(Signed192 other) =>
 691        ((High ^ other.High)
 692         | (Middle ^ other.Middle)
 693         | (Low ^ other.Low)) == 0UL;
 94}