< Summary

Information
Class: FixedMathSharp.Fixed64Extensions
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Extensions/Fixed64.Extensions.cs
Line coverage
100%
Covered lines: 83
Uncovered lines: 0
Coverable lines: 83
Total lines: 244
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/Extensions/Fixed64.Extensions.cs

#LineLine coverage
 1using System;
 2using System.Runtime.CompilerServices;
 3
 4namespace FixedMathSharp
 5{
 6    public static class Fixed64Extensions
 7    {
 8        #region Fixed64 Operations
 9
 10        /// <inheritdoc cref="Fixed64.Sign(Fixed64)" />
 11        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 12        public static int Sign(this Fixed64 value)
 613        {
 614            return Fixed64.Sign(value);
 615        }
 16
 17        /// <inheritdoc cref="Fixed64.IsInteger(Fixed64)" />
 18        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 19        public static bool IsInteger(this Fixed64 value)
 620        {
 621            return Fixed64.IsInteger(value);
 622        }
 23
 24        /// <inheritdoc cref="FixedMath.Squared(Fixed64)" />
 25        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 26        public static Fixed64 Squared(this Fixed64 value)
 127        {
 128            return FixedMath.Squared(value);
 129        }
 30
 31        /// <inheritdoc cref="FixedMath.Round(Fixed64, MidpointRounding)" />
 32        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 33        public static Fixed64 Round(this Fixed64 value, MidpointRounding mode = MidpointRounding.ToEven)
 334        {
 335            return FixedMath.Round(value, mode);
 336        }
 37
 38        /// <inheritdoc cref="FixedMath.RoundToPrecision(Fixed64, int, MidpointRounding)" />
 39        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 40        public static Fixed64 RoundToPrecision(this Fixed64 value, int places, MidpointRounding mode = MidpointRounding.
 141        {
 142            return FixedMath.RoundToPrecision(value, places, mode);
 143        }
 44
 45        /// <inheritdoc cref="FixedMath.ClampOne(Fixed64)" />
 46        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 47        public static Fixed64 ClampOne(this Fixed64 f1)
 648        {
 649            return FixedMath.ClampOne(f1);
 650        }
 51
 52        /// <inheritdoc cref="FixedMath.Clamp01(Fixed64)" />
 53        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 54        public static Fixed64 Clamp01(this Fixed64 f1)
 155        {
 156            return FixedMath.Clamp01(f1);
 157        }
 58
 59        /// <inheritdoc cref="FixedMath.Abs(Fixed64)" />
 60        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 61        public static Fixed64 Abs(this Fixed64 value)
 113462        {
 113463            return FixedMath.Abs(value);
 113464        }
 65
 66        /// <summary>
 67        /// Checks if the absolute value of x is less than y.
 68        /// </summary>
 69        /// <param name="x">The value to compare.</param>
 70        /// <param name="y">The comparison threshold.</param>
 71        /// <returns>True if |x| &lt; y; otherwise false.</returns>
 72        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 73        public static bool AbsLessThan(this Fixed64 x, Fixed64 y)
 174        {
 175            return Abs(x) < y;
 176        }
 77
 78        /// <inheritdoc cref="FixedMath.FastAdd(Fixed64, Fixed64)" />
 79        public static Fixed64 FastAdd(this Fixed64 a, Fixed64 b)
 180        {
 181            return FixedMath.FastAdd(a, b);
 182        }
 83
 84        /// <inheritdoc cref="FixedMath.FastSub(Fixed64, Fixed64)" />
 85        public static Fixed64 FastSub(this Fixed64 a, Fixed64 b)
 186        {
 187            return FixedMath.FastSub(a, b);
 188        }
 89
 90        /// <inheritdoc cref="FixedMath.FastMul(Fixed64, Fixed64)" />
 91        public static Fixed64 FastMul(this Fixed64 a, Fixed64 b)
 192        {
 193            return FixedMath.FastMul(a, b);
 194        }
 95
 96        /// <inheritdoc cref="FixedMath.FastMod(Fixed64, Fixed64)" />
 97        public static Fixed64 FastMod(this Fixed64 a, Fixed64 b)
 198        {
 199            return FixedMath.FastMod(a, b);
 1100        }
 101
 102        /// <inheritdoc cref="FixedMath.Floor(Fixed64)" />
 103        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 104        public static Fixed64 Floor(this Fixed64 value)
 30105        {
 30106            return FixedMath.Floor(value);
 30107        }
 108
 109        /// <inheritdoc cref="FixedMath.Ceiling(Fixed64)" />
 110        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 111        public static Fixed64 Ceiling(this Fixed64 value)
 1112        {
 1113            return FixedMath.Ceiling(value);
 1114        }
 115
 116        /// <summary>
 117        /// Rounds the Fixed64 value to the nearest integer.
 118        /// </summary>
 119        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 120        public static int RoundToInt(this Fixed64 x)
 6121        {
 6122            return (int)FixedMath.Round(x);
 6123        }
 124
 125        /// <summary>
 126        /// Rounds up the Fixed64 value to the nearest integer.
 127        /// </summary>
 128        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 129        public static int CeilToInt(this Fixed64 x)
 1130        {
 1131            return (int)FixedMath.Ceiling(x);
 1132        }
 133
 134        /// <summary>
 135        /// Rounds down the Fixed64 value to the nearest integer.
 136        /// </summary>
 137        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 138        public static int FloorToInt(this Fixed64 x)
 1139        {
 1140            return (int)Floor(x);
 1141        }
 142
 143        #endregion
 144
 145        #region Conversion
 146
 147        /// <summary>
 148        /// Converts the Fixed64 value to a string formatted to 2 decimal places.
 149        /// </summary>
 150        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 151        public static string ToFormattedString(this Fixed64 f1)
 1152        {
 1153            return f1.ToPreciseFloat().ToString("0.##");
 1154        }
 155
 156        /// <summary>
 157        /// Converts the Fixed64 value to a double with specified decimal precision.
 158        /// </summary>
 159        /// <param name="f1">The Fixed64 value to convert.</param>
 160        /// <param name="precision">The number of decimal places to round to.</param>
 161        /// <returns>The formatted double value.</returns>
 162        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 163        public static double ToFormattedDouble(this Fixed64 f1, int precision = 2)
 326164        {
 326165            return Math.Round((double)f1, precision, MidpointRounding.AwayFromZero);
 326166        }
 167
 168        /// <summary>
 169        /// Converts the Fixed64 value to a float with 2 decimal points of precision.
 170        /// </summary>
 171        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 172        public static float ToFormattedFloat(this Fixed64 f1)
 2173        {
 2174            return (float)ToFormattedDouble(f1);
 2175        }
 176
 177        /// <summary>
 178        /// Converts the Fixed64 value to a precise float representation (without rounding).
 179        /// </summary>
 180        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 181        public static float ToPreciseFloat(this Fixed64 f1)
 7182        {
 7183            return (float)(double)f1;
 7184        }
 185
 186        /// <summary>
 187        /// Converts the angle in degrees to radians.
 188        /// </summary>
 189        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 190        public static Fixed64 ToRadians(this Fixed64 angleInDegrees)
 2191        {
 2192            return FixedMath.DegToRad(angleInDegrees);
 2193        }
 194
 195        /// <summary>
 196        /// Converts the angle in radians to degree.
 197        /// </summary>
 198        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 199        public static Fixed64 ToDegree(this Fixed64 angleInRadians)
 1200        {
 1201            return FixedMath.RadToDeg(angleInRadians);
 1202        }
 203
 204        #endregion
 205
 206        #region Equality
 207
 208        /// <summary>
 209        /// Checks if the value is greater than epsilon (positive or negative).
 210        /// Useful for determining if a value is effectively non-zero with a given precision.
 211        /// </summary>
 212        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 213        public static bool MoreThanEpsilon(this Fixed64 d)
 2214        {
 2215            return d.Abs() > Fixed64.Epsilon;
 2216        }
 217
 218        /// <summary>
 219        /// Checks if the value is less than epsilon (i.e., effectively zero).
 220        /// Useful for determining if a value is close enough to zero with a given precision.
 221        /// </summary>
 222        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 223        public static bool LessThanEpsilon(this Fixed64 d)
 2224        {
 2225            return d.Abs() < Fixed64.Epsilon;
 2226        }
 227
 228        /// <summary>
 229        /// Helper method to compare individual vector components for approximate equality, allowing a fractional differ
 230        /// Handles zero components by only using the allowed percentage difference.
 231        /// </summary>
 232        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 233        public static bool FuzzyComponentEqual(this Fixed64 a, Fixed64 b, Fixed64 percentage)
 254234        {
 254235            var diff = (a - b).Abs();
 254236            var allowedErr = a.Abs() * percentage;
 237            // Compare directly to percentage if a is zero
 238            // Otherwise, use percentage of a's magnitude
 254239            return a == Fixed64.Zero ? diff <= percentage : diff <= allowedErr;
 254240        }
 241
 242        #endregion
 243    }
 244}