< Summary

Information
Class: FixedMathSharp.Signed320
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Wide/Signed320.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 80
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor(...)100%11100%
get_IsZero()100%11100%
get_Sign()100%44100%
NarrowValue(...)100%11100%
TryNarrowSigned(...)100%1010100%
ExtendValue(...)100%22100%
Equals(...)100%11100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// Signed320.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 five-word value used by exact geometry for products and
 14/// differences of three-component dot products.
 15/// </summary>
 16internal readonly struct Signed320
 17{
 118    public static readonly Signed320 One = ExtendValue(Signed192.One);
 19
 20    internal readonly ulong Word4;
 21    internal readonly ulong Word3;
 22    internal readonly ulong Word2;
 23    internal readonly ulong Word1;
 24    internal readonly ulong Word0;
 25
 26    internal Signed320(ulong word4, ulong word3, ulong word2, ulong word1, ulong word0)
 27    {
 654263828        Word4 = word4;
 654263829        Word3 = word3;
 654263830        Word2 = word2;
 654263831        Word1 = word1;
 654263832        Word0 = word0;
 654263833    }
 34
 520042635    internal bool IsZero => (Word4 | Word3 | Word2 | Word1 | Word0) == 0UL;
 36
 508356937    internal int Sign => IsZero ? 0 : (Word4 & (1UL << 63)) != 0UL ? -1 : 1;
 38
 39    /// <summary>
 40    /// Narrow a Signed576 value to a Signed320 value, discarding the upper 256 bits.
 41    /// </summary>
 42    internal static Signed320 NarrowValue(Signed576 value) =>
 8455443        new(value.Word4,
 8455444            value.Word3,
 8455445            value.Word2,
 8455446            value.Word1,
 8455447            value.Word0);
 48
 49    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 50    internal static bool TryNarrowSigned(Signed576 value, out Signed320 result)
 51    {
 41702652        ulong extension = (value.Word4 & (1UL << 63)) != 0UL ? ulong.MaxValue : 0UL;
 41702653        if (value.Word8 != extension || value.Word7 != extension
 41702654            || value.Word6 != extension || value.Word5 != extension)
 55        {
 7156456            result = default;
 7156457            return false;
 58        }
 59
 34546260        result = new Signed320(value.Word4, value.Word3, value.Word2, value.Word1, value.Word0);
 34546261        return true;
 62    }
 63
 64    /// <summary>
 65    /// Sign-extends an exact three-word value to five words.
 66    /// </summary>
 67    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 68    internal static Signed320 ExtendValue(Signed192 value)
 69    {
 145386070        ulong extension = value.Sign < 0 ? ulong.MaxValue : 0UL;
 145386071        return new Signed320(extension, extension, value.High, value.Middle, value.Low);
 72    }
 73
 74    internal bool Equals(Signed320 other) =>
 1621375        ((Word4 ^ other.Word4)
 1621376         | (Word3 ^ other.Word3)
 1621377         | (Word2 ^ other.Word2)
 1621378         | (Word1 ^ other.Word1)
 1621379         | (Word0 ^ other.Word0)) == 0UL;
 80}