< Summary

Information
Class: FixedMathSharp.Fixed64Extensions
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Scalars/Fixed64.Extensions.cs
Line coverage
100%
Covered lines: 83
Uncovered lines: 0
Coverable lines: 83
Total lines: 246
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Sign(...)100%11100%
IsInteger(...)100%11100%
Squared(...)100%11100%
Round(...)100%11100%
RoundToPrecision(...)100%11100%
ClampOne(...)100%11100%
Clamp01(...)100%11100%
Abs(...)100%11100%
AbsLessThan(...)100%11100%
FastAdd(...)100%11100%
FastSub(...)100%11100%
FastMul(...)100%11100%
FastMod(...)100%11100%
Floor(...)100%11100%
Ceiling(...)100%11100%
RoundToInt(...)100%11100%
CeilToInt(...)100%11100%
FloorToInt(...)100%11100%
ToFormattedString(...)100%11100%
ToFormattedDouble(...)100%11100%
ToFormattedFloat(...)100%11100%
ToPreciseFloat(...)100%11100%
ToRadians(...)100%11100%
ToDegree(...)100%11100%
MoreThanEpsilon(...)100%11100%
LessThanEpsilon(...)100%11100%
FuzzyComponentEqual(...)100%22100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Scalars/Fixed64.Extensions.cs

#LineLine coverage
 1using System;
 2using System.Runtime.CompilerServices;
 3
 4namespace FixedMathSharp;
 5
 6/// <summary>
 7/// Provides extension methods for the Fixed64 type, enabling additional mathematical, conversion, and comparison operat
 8/// </summary>
 9public static class Fixed64Extensions
 10{
 11    #region Fixed64 Operations
 12
 13    /// <inheritdoc cref="Fixed64.Sign(Fixed64)" />
 14    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 15    public static int Sign(this Fixed64 value)
 1416    {
 1417        return Fixed64.Sign(value);
 1418    }
 19
 20    /// <inheritdoc cref="Fixed64.IsInteger(Fixed64)" />
 21    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 22    public static bool IsInteger(this Fixed64 value)
 623    {
 624        return Fixed64.IsInteger(value);
 625    }
 26
 27    /// <inheritdoc cref="FixedMath.Squared(Fixed64)" />
 28    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 29    public static Fixed64 Squared(this Fixed64 value)
 130    {
 131        return FixedMath.Squared(value);
 132    }
 33
 34    /// <inheritdoc cref="FixedMath.Round(Fixed64, MidpointRounding)" />
 35    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 36    public static Fixed64 Round(this Fixed64 value, MidpointRounding mode = MidpointRounding.ToEven)
 337    {
 338        return FixedMath.Round(value, mode);
 339    }
 40
 41    /// <inheritdoc cref="FixedMath.RoundToPrecision(Fixed64, int, MidpointRounding)" />
 42    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 43    public static Fixed64 RoundToPrecision(this Fixed64 value, int places, MidpointRounding mode = MidpointRounding.ToEv
 144    {
 145        return FixedMath.RoundToPrecision(value, places, mode);
 146    }
 47
 48    /// <inheritdoc cref="FixedMath.ClampOne(Fixed64)" />
 49    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 50    public static Fixed64 ClampOne(this Fixed64 f1)
 1051    {
 1052        return FixedMath.ClampOne(f1);
 1053    }
 54
 55    /// <inheritdoc cref="FixedMath.Clamp01(Fixed64)" />
 56    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 57    public static Fixed64 Clamp01(this Fixed64 f1)
 158    {
 159        return FixedMath.Clamp01(f1);
 160    }
 61
 62    /// <inheritdoc cref="FixedMath.Abs(Fixed64)" />
 63    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 64    public static Fixed64 Abs(this Fixed64 value)
 223765    {
 223766        return FixedMath.Abs(value);
 223767    }
 68
 69    /// <summary>
 70    /// Checks if the absolute value of x is less than y.
 71    /// </summary>
 72    /// <param name="x">The value to compare.</param>
 73    /// <param name="y">The comparison threshold.</param>
 74    /// <returns>True if |x| &lt; y; otherwise false.</returns>
 75    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 76    public static bool AbsLessThan(this Fixed64 x, Fixed64 y)
 177    {
 178        return Abs(x) < y;
 179    }
 80
 81    /// <inheritdoc cref="FixedMath.FastAdd(Fixed64, Fixed64)" />
 82    public static Fixed64 FastAdd(this Fixed64 a, Fixed64 b)
 183    {
 184        return FixedMath.FastAdd(a, b);
 185    }
 86
 87    /// <inheritdoc cref="FixedMath.FastSub(Fixed64, Fixed64)" />
 88    public static Fixed64 FastSub(this Fixed64 a, Fixed64 b)
 189    {
 190        return FixedMath.FastSub(a, b);
 191    }
 92
 93    /// <inheritdoc cref="FixedMath.FastMul(Fixed64, Fixed64)" />
 94    public static Fixed64 FastMul(this Fixed64 a, Fixed64 b)
 195    {
 196        return FixedMath.FastMul(a, b);
 197    }
 98
 99    /// <inheritdoc cref="FixedMath.FastMod(Fixed64, Fixed64)" />
 100    public static Fixed64 FastMod(this Fixed64 a, Fixed64 b)
 1101    {
 1102        return FixedMath.FastMod(a, b);
 1103    }
 104
 105    /// <inheritdoc cref="FixedMath.Floor(Fixed64)" />
 106    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 107    public static Fixed64 Floor(this Fixed64 value)
 34108    {
 34109        return FixedMath.Floor(value);
 34110    }
 111
 112    /// <inheritdoc cref="FixedMath.Ceiling(Fixed64)" />
 113    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 114    public static Fixed64 Ceiling(this Fixed64 value)
 1115    {
 1116        return FixedMath.Ceiling(value);
 1117    }
 118
 119    /// <summary>
 120    /// Rounds the Fixed64 value to the nearest integer.
 121    /// </summary>
 122    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 123    public static int RoundToInt(this Fixed64 x)
 10124    {
 10125        return (int)FixedMath.Round(x);
 10126    }
 127
 128    /// <summary>
 129    /// Rounds up the Fixed64 value to the nearest integer.
 130    /// </summary>
 131    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 132    public static int CeilToInt(this Fixed64 x)
 1133    {
 1134        return (int)FixedMath.Ceiling(x);
 1135    }
 136
 137    /// <summary>
 138    /// Rounds down the Fixed64 value to the nearest integer.
 139    /// </summary>
 140    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 141    public static int FloorToInt(this Fixed64 x)
 1142    {
 1143        return (int)Floor(x);
 1144    }
 145
 146    #endregion
 147
 148    #region Conversion
 149
 150    /// <summary>
 151    /// Converts the Fixed64 value to a string formatted to 2 decimal places.
 152    /// </summary>
 153    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 154    public static string ToFormattedString(this Fixed64 f1)
 1155    {
 1156        return f1.ToPreciseFloat().ToString("0.##");
 1157    }
 158
 159    /// <summary>
 160    /// Converts the Fixed64 value to a double with specified decimal precision.
 161    /// </summary>
 162    /// <param name="f1">The Fixed64 value to convert.</param>
 163    /// <param name="precision">The number of decimal places to round to.</param>
 164    /// <returns>The formatted double value.</returns>
 165    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 166    public static double ToFormattedDouble(this Fixed64 f1, int precision = 2)
 2298167    {
 2298168        return Math.Round((double)f1, precision, MidpointRounding.AwayFromZero);
 2298169    }
 170
 171    /// <summary>
 172    /// Converts the Fixed64 value to a float with 2 decimal points of precision.
 173    /// </summary>
 174    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 175    public static float ToFormattedFloat(this Fixed64 f1)
 2176    {
 2177        return (float)ToFormattedDouble(f1);
 2178    }
 179
 180    /// <summary>
 181    /// Converts the Fixed64 value to a precise float representation (without rounding).
 182    /// </summary>
 183    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 184    public static float ToPreciseFloat(this Fixed64 f1)
 11185    {
 11186        return (float)(double)f1;
 11187    }
 188
 189    /// <summary>
 190    /// Converts the angle in degrees to radians.
 191    /// </summary>
 192    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 193    public static Fixed64 ToRadians(this Fixed64 angleInDegrees)
 2194    {
 2195        return FixedMath.DegToRad(angleInDegrees);
 2196    }
 197
 198    /// <summary>
 199    /// Converts the angle in radians to degree.
 200    /// </summary>
 201    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 202    public static Fixed64 ToDegree(this Fixed64 angleInRadians)
 1203    {
 1204        return FixedMath.RadToDeg(angleInRadians);
 1205    }
 206
 207    #endregion
 208
 209    #region Equality
 210
 211    /// <summary>
 212    /// Checks if the value is greater than epsilon (positive or negative).
 213    /// Useful for determining if a value is effectively non-zero with a given precision.
 214    /// </summary>
 215    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 216    public static bool MoreThanEpsilon(this Fixed64 d)
 2217    {
 2218        return d.Abs() > Fixed64.Epsilon;
 2219    }
 220
 221    /// <summary>
 222    /// Checks if the value is less than epsilon (i.e., effectively zero).
 223    /// Useful for determining if a value is close enough to zero with a given precision.
 224    /// </summary>
 225    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 226    public static bool LessThanEpsilon(this Fixed64 d)
 392227    {
 392228        return d.Abs() < Fixed64.Epsilon;
 392229    }
 230
 231    /// <summary>
 232    /// Helper method to compare individual vector components for approximate equality, allowing a fractional difference
 233    /// Handles zero components by only using the allowed percentage difference.
 234    /// </summary>
 235    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 236    public static bool FuzzyComponentEqual(this Fixed64 a, Fixed64 b, Fixed64 percentage)
 390237    {
 390238        var diff = (a - b).Abs();
 390239        var allowedErr = a.Abs() * percentage;
 240        // Compare directly to percentage if a is zero
 241        // Otherwise, use percentage of a's magnitude
 390242        return a.LessThanEpsilon() ? diff <= percentage : diff <= allowedErr;
 390243    }
 244
 245    #endregion
 246}