Last active
October 25, 2023 08:28
-
-
Save xoofx/e4f5e21495104e2183c402575d32accd to your computer and use it in GitHub Desktop.
Math template used for https://github.com/dotnet/runtime/issues/93513
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#@ template debug="false" hostspecific="false" language="C#" #> | |
<#@ assembly name="System.Core" #> | |
<#@ import namespace="System.Linq" #> | |
<#@ import namespace="System.Text" #> | |
<#@ import namespace="System.Collections.Generic" #> | |
<#@ output extension=".txt" #> | |
<# | |
var vectors = new [] { "Vector64", "Vector128", "Vector256", "Vector512", "Vector", "Vector2", "Vector3", "Vector4" }; | |
var templates = new string[0]; | |
string genT; | |
string ns; | |
string genTConstraint; | |
#> | |
<# foreach(var v in vectors) { bool isNumerics = v == "Vector2" || v == "Vector3" || v == "Vector4"; #> | |
<# if (isNumerics) { templates = new [] { "" }; genT = ""; ns = "System.Numerics"; genTConstraint = ""; #> | |
namespace <#= ns #>; | |
public struct <#= v #> | |
<# } else { templates = new [] { "<float>", "<double>" }; genT = "<T>"; ns = "System.Runtime.Intrinsics"; genTConstraint = " where T: unmanaged"; #> | |
namespace <#= ns #>; | |
public static class <#= v #> | |
<# } #> | |
{ | |
<# foreach(var t in templates) {#> | |
<# if (isNumerics) {#> | |
// IFloatingPointIeee754 | |
public static <#= v #> Epsilon { get; } | |
public static <#= v #> NaN { get; } | |
public static <#= v #> NegativeInfinity { get; } | |
public static <#= v #> NegativeZero { get; } | |
public static <#= v #> PositiveInfinity { get; } | |
// IFloatingPointConstants | |
public static <#= v #> E { get; } | |
public static <#= v #> Pi { get; } | |
public static <#= v #> Tau { get; } | |
// INumberBase | |
public static <#= v #> Radix { get; } | |
<# } #> | |
// Equivalent implementing IHyperbolicFunctions<<#= ns #>.<#= v #><#= t #>> | |
public static <#= v #><#= t #> Acosh(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Asinh(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Atanh(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Cosh(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Sinh(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Tanh(<#= v #><#= t #> x); | |
// Equivalent implementing ITrigonometricFunctions<<#= ns #>.<#= v #><#= t #>> | |
public static <#= v #><#= t #> Acos(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> AcosPi(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Asin(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> AsinPi(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Atan(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> AtanPi(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Cos(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> CosPi(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> DegreesToRadians(<#= v #><#= t #> degrees); | |
public static <#= v #><#= t #> RadiansToDegrees(<#= v #><#= t #> radians); | |
public static <#= v #><#= t #> Sin(<#= v #><#= t #> x); | |
public static (<#= v #><#= t #> Sin, <#= v #><#= t #> Cos) SinCos(<#= v #><#= t #> x); | |
public static (<#= v #><#= t #> SinPi, <#= v #><#= t #> CosPi) SinCosPi(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> SinPi(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Tan(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> TanPi(<#= v #><#= t #> x); | |
// Equivalent implementing ILogarithmicFunctions<<#= ns #>.<#= v #><#= t #>> | |
public static <#= v #><#= t #> Log(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Log(<#= v #><#= t #> x, <#= v #><#= t #> newBase); | |
public static <#= v #><#= t #> LogP1(<#= v #><#= t #> x) => Log(x + <#= v #><#= t #>.One); | |
public static <#= v #><#= t #> Log2(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Log2P1(<#= v #><#= t #> x) => Log2(x + <#= v #><#= t #>.One); | |
public static <#= v #><#= t #> Log10(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Log10P1(<#= v #><#= t #> x) => Log10(x + <#= v #><#= t #>.One); | |
// Equivalent implementing IExponentialFunctions<<#= ns #>.<#= v #><#= t #>> | |
public static <#= v #><#= t #> Exp(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> ExpM1(<#= v #><#= t #> x) => Exp(x) - <#= v #><#= t #>.One; | |
public static <#= v #><#= t #> Exp2(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Exp2M1(<#= v #><#= t #> x) => Exp2(x) - <#= v #><#= t #>.One; | |
public static <#= v #><#= t #> Exp10(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Exp10M1(<#= v #><#= t #> x) => Exp10(x) - <#= v #><#= t #>.One; | |
// Equivalent implementing IPowerFunctions<<#= ns #>.<#= v #><#= t #>> | |
public static <#= v #><#= t #> Pow(<#= v #><#= t #> x, <#= v #><#= t #> y); | |
// Equivalent implementing IRootFunctions<<#= ns #>.<#= v #><#= t #>> | |
public static <#= v #><#= t #> Cbrt(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Hypot(<#= v #><#= t #> x, <#= v #><#= t #> y); | |
public static <#= v #><#= t #> RootN(<#= v #><#= t #> x, int n); | |
public static <#= v #><#= t #> Sqrt(<#= v #><#= t #> x); | |
// IFloatingPoint<TSelf> | |
public static <#= v #><#= t #> Round(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> Round(<#= v #><#= t #> x, int digits); | |
public static <#= v #><#= t #> Round(<#= v #><#= t #> x, MidpointRounding mode); | |
public static <#= v #><#= t #> Round(<#= v #><#= t #> x, int digits, MidpointRounding mode); | |
public static <#= v #><#= t #> Truncate(<#= v #><#= t #> x); | |
// IFloatingPointIeee754<TSelf> | |
public static <#= v #><#= t #> Atan2(<#= v #><#= t #> y, <#= v #><#= t #> x); | |
public static <#= v #><#= t #> Atan2Pi(<#= v #><#= t #> y, <#= v #><#= t #> x); | |
public static <#= v #><#= t #> BitDecrement(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> BitIncrement(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> FusedMultiplyAdd(<#= v #><#= t #> left, <#= v #><#= t #> right, <#= v #><#= t #> addend); | |
public static <#= v #><#= t #> Lerp(<#= v #><#= t #> value1, <#= v #><#= t #> value2, <#= v #><#= t #> amount); | |
public static <#= v #><#= t #> ReciprocalEstimate(<#= v #><#= t #> x); | |
public static <#= v #><#= t #> ReciprocalSqrtEstimate(<#= v #><#= t #> x); | |
<# } #> | |
// INumber<T> -- these also work for integer types | |
public static <#= v #><#= genT #> Clamp<#= genT #>(<#= v #><#= genT #> value, <#= v #><#= genT #> min, <#= v #><#= genT #> max)<#= genTConstraint #>; | |
public static <#= v #><#= genT #> CopySign<#= genT #>(<#= v #><#= genT #> value, <#= v #><#= genT #> sign)<#= genTConstraint #>; | |
public static <#= v #><#= genT #> MaxNumber<#= genT #>(<#= v #><#= genT #> x, <#= v #><#= genT #> y)<#= genTConstraint #>; | |
public static <#= v #><#= genT #> MinNumber<#= genT #>(<#= v #><#= genT #> x, <#= v #><#= genT #> y)<#= genTConstraint #>; | |
// INumberBase<T> -- these also work for integer types | |
public static <#= v #><#= genT #> MaxMagnitude<#= genT #>(<#= v #><#= genT #> x, <#= v #><#= genT #> y)<#= genTConstraint #>; | |
public static <#= v #><#= genT #> MaxMagnitudeNumber<#= genT #>(<#= v #><#= genT #> x, <#= v #><#= genT #> y)<#= genTConstraint #>; | |
public static <#= v #><#= genT #> MinMagnitude<#= genT #>(<#= v #><#= genT #> x, <#= v #><#= genT #> y)<#= genTConstraint #>; | |
public static <#= v #><#= genT #> MinMagnitudeNumber<#= genT #>(<#= v #><#= genT #> x, <#= v #><#= genT #> y)<#= genTConstraint #>; | |
} | |
<# } #> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment