Skip to content

Commit

Permalink
refactor: replace T.Saturate for float types with generic math
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Nov 14, 2024
1 parent cb7e130 commit 7af3c96
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- X10D: Removed `IEnumerable<T>.LowestCommonMultiple` for all integer types in favour of generic math.
- X10D: Removed `IEnumerable<T>.Product` for all integer types in favour of generic math.
- X10D: Removed `IEnumerable<T>.RangeTo` for all integer types in favour of generic math.
- X10D: Removed `T.Saturate` for all floating-point types in favour of generic math.
- X10D: Removed `T.Sign` for all numeric types in favour of generic math.
- X10D: Removed `T.Wrap` for all numeric types in favour of generic math.

Expand Down
13 changes: 0 additions & 13 deletions X10D/src/Math/DecimalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,6 @@ public static decimal Round(this decimal value, decimal nearest)
return System.Math.Round(value / nearest) * nearest;
}

/// <summary>
/// Saturates this decimal number.
/// </summary>
/// <param name="value">The value to saturate.</param>
/// <returns>The saturated value.</returns>
/// <remarks>This method clamps <paramref name="value" /> between 0 and 1.</remarks>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static decimal Saturate(this decimal value)
{
return System.Math.Clamp(value, 0.0m, 1.0m);
}

/// <summary>
/// Returns the square root of this decimal number.
/// </summary>
Expand Down
13 changes: 0 additions & 13 deletions X10D/src/Math/DoubleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,6 @@ public static double Round(this double value, double nearest)
return System.Math.Round(value / nearest) * nearest;
}

/// <summary>
/// Saturates this double-precision floating-point number.
/// </summary>
/// <param name="value">The value to saturate.</param>
/// <returns>The saturated value.</returns>
/// <remarks>This method clamps <paramref name="value" /> between 0 and 1.</remarks>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static double Saturate(this double value)
{
return System.Math.Clamp(value, 0.0, 1.0);
}

/// <summary>
/// Returns the sine of the specified angle.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions X10D/src/Math/NumberExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ public static TNumber Mod<TNumber>(this TNumber dividend, TNumber divisor)
return r < TNumber.Zero ? r + divisor : r;
}

/// <summary>
/// Saturates this number.
/// </summary>
/// <param name="value">The value to saturate.</param>
/// <returns>The saturated value.</returns>
/// <remarks>
/// This method clamps <paramref name="value" /> between <see cref="TNumber.Zero" /> and <see cref="TNumber.One" />.

Check warning on line 122 in X10D/src/Math/NumberExtensions.cs

View workflow job for this annotation

GitHub Actions / Build & Test

XML comment has cref attribute 'Zero' that could not be resolved

Check warning on line 122 in X10D/src/Math/NumberExtensions.cs

View workflow job for this annotation

GitHub Actions / Build & Test

XML comment has cref attribute 'One' that could not be resolved

Check warning on line 122 in X10D/src/Math/NumberExtensions.cs

View workflow job for this annotation

GitHub Actions / Build & Test

XML comment has cref attribute 'Zero' that could not be resolved

Check warning on line 122 in X10D/src/Math/NumberExtensions.cs

View workflow job for this annotation

GitHub Actions / Build & Test

XML comment has cref attribute 'One' that could not be resolved

Check warning on line 122 in X10D/src/Math/NumberExtensions.cs

View workflow job for this annotation

GitHub Actions / Build & Test

XML comment has cref attribute 'Zero' that could not be resolved

Check warning on line 122 in X10D/src/Math/NumberExtensions.cs

View workflow job for this annotation

GitHub Actions / Build & Test

XML comment has cref attribute 'One' that could not be resolved

Check warning on line 122 in X10D/src/Math/NumberExtensions.cs

View workflow job for this annotation

GitHub Actions / Build & Test

XML comment has cref attribute 'Zero' that could not be resolved

Check warning on line 122 in X10D/src/Math/NumberExtensions.cs

View workflow job for this annotation

GitHub Actions / Build & Test

XML comment has cref attribute 'One' that could not be resolved
/// </remarks>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static TNumber Saturate<TNumber>(this TNumber value)
where TNumber : INumber<TNumber>
{
return TNumber.Clamp(value, TNumber.Zero, TNumber.One);
}

/// <summary>
/// Returns an integer that indicates the sign of this number.
/// </summary>
Expand Down

0 comments on commit 7af3c96

Please sign in to comment.