Skip to content

Commit

Permalink
Exposing AcosPi, AsinPi, Atan2Pi, AtanPi, CosPi, SinPi, and TanPi for…
Browse files Browse the repository at this point in the history
… ITrigonometricFunctions (#71033)

* Exposing AcosPi, AsinPi, Atan2Pi, AtanPi, CosPi, SinPi, and TanPi for ITrigonometricFunctions

* Adding tests for AcosPi, AsinPi, Atan2Pi, AtanPi, CosPi, SinPi, and TanPi

* Fixing the handling of AcosPi, AsinPi, and AtanPi tests on WASM/Unix
  • Loading branch information
tannergooding authored Jun 22, 2022
1 parent 9d3f060 commit 0855da7
Show file tree
Hide file tree
Showing 11 changed files with 1,817 additions and 89 deletions.
483 changes: 469 additions & 14 deletions src/libraries/System.Private.CoreLib/src/System/Double.cs

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions src/libraries/System.Private.CoreLib/src/System/Half.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1828,18 +1828,33 @@ private static bool TryConvertTo<TOther>(Half value, [NotNullWhen(true)] out TOt
/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Acos(TSelf)" />
public static Half Acos(Half x) => (Half)MathF.Acos((float)x);

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.AcosPi(TSelf)" />
public static Half AcosPi(Half x) => (Half)float.AcosPi((float)x);

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Asin(TSelf)" />
public static Half Asin(Half x) => (Half)MathF.Asin((float)x);

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.AsinPi(TSelf)" />
public static Half AsinPi(Half x) => (Half)float.AsinPi((float)x);

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Atan(TSelf)" />
public static Half Atan(Half x) => (Half)MathF.Atan((float)x);

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Atan2(TSelf, TSelf)" />
public static Half Atan2(Half y, Half x) => (Half)MathF.Atan2((float)y, (float)x);

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Atan2Pi(TSelf, TSelf)" />
public static Half Atan2Pi(Half y, Half x) => (Half)float.Atan2Pi((float)y, (float)x);

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.AtanPi(TSelf)" />
public static Half AtanPi(Half x) => (Half)float.AtanPi((float)x);

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Cos(TSelf)" />
public static Half Cos(Half x) => (Half)MathF.Cos((float)x);

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.CosPi(TSelf)" />
public static Half CosPi(Half x) => (Half)float.CosPi((float)x);

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Sin(TSelf)" />
public static Half Sin(Half x) => (Half)MathF.Sin((float)x);

Expand All @@ -1850,29 +1865,14 @@ public static (Half Sin, Half Cos) SinCos(Half x)
return ((Half)sin, (Half)cos);
}

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.SinPi(TSelf)" />
public static Half SinPi(Half x) => (Half)float.SinPi((float)x);

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Tan(TSelf)" />
public static Half Tan(Half x) => (Half)MathF.Tan((float)x);

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.AcosPi(TSelf)" />
// public static Half AcosPi(Half x) => (Half)MathF.AcosPi((float)x);

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.AsinPi(TSelf)" />
// public static Half AsinPi(Half x) => (Half)MathF.AsinPi((float)x);

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.AtanPi(TSelf)" />
// public static Half AtanPi(Half x) => (Half)MathF.AtanPi((float)x);

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Atan2Pi(TSelf)" />
// public static Half Atan2Pi(Half y, Half x) => (Half)MathF.Atan2Pi((float)y, (float)x);

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.CosPi(TSelf)" />
// public static Half CosPi(Half x) => (Half)MathF.CosPi((float)x);

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.SinPi(TSelf)" />
// public static Half SinPi(Half x) => (Half)MathF.SinPi((float)x, (float)y);

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.TanPi(TSelf)" />
// public static Half TanPi(Half x) => (Half)MathF.TanPi((float)x, (float)y);
/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.TanPi(TSelf)" />
public static Half TanPi(Half x) => (Half)float.TanPi((float)x);

//
// IUnaryNegationOperators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,95 @@ public interface ITrigonometricFunctions<TSelf>
where TSelf : ITrigonometricFunctions<TSelf>, INumberBase<TSelf>
{
/// <summary>Computes the arc-cosine of a value.</summary>
/// <param name="x">The value, in radians, whose arc-cosine is to be computed.</param>
/// <param name="x">The value whose arc-cosine is to be computed.</param>
/// <returns>The arc-cosine of <paramref name="x" />.</returns>
/// <remarks>This computes <c>arccos(x)</c> in the interval <c>[+0, +π]</c> radians.</remarks>
static abstract TSelf Acos(TSelf x);

/// <summary>Computes the arc-cosine of a value and divides the result by <c>pi</c>.</summary>
/// <param name="x">The value whose arc-cosine is to be computed.</param>
/// <returns>The arc-cosine of <paramref name="x" />, divided by <c>pi</c>.</returns>
/// <remarks>This computes <c>arccos(x) / π</c> in the interval <c>[-0.5, +0.5]</c>.</remarks>
static abstract TSelf AcosPi(TSelf x);

/// <summary>Computes the arc-sine of a value.</summary>
/// <param name="x">The value, in radians, whose arc-sine is to be computed.</param>
/// <param name="x">The value whose arc-sine is to be computed.</param>
/// <returns>The arc-sine of <paramref name="x" />.</returns>
/// <remarks>This computes <c>arcsin(x)</c> in the interval <c>[-π / 2, +π / 2]</c> radians.</remarks>
static abstract TSelf Asin(TSelf x);

/// <summary>Computes the arc-sine of a value and divides the result by <c>pi</c>.</summary>
/// <param name="x">The value whose arc-sine is to be computed.</param>
/// <returns>The arc-sine of <paramref name="x" />, divided by <c>pi</c>.</returns>
/// <remarks>This computes <c>arcsin(x) / π</c> in the interval <c>[-0.5, +0.5]</c>.</remarks>
static abstract TSelf AsinPi(TSelf x);

/// <summary>Computes the arc-tangent of a value.</summary>
/// <param name="x">The value, in radians, whose arc-tangent is to be computed.</param>
/// <param name="x">The value whose arc-tangent is to be computed.</param>
/// <returns>The arc-tangent of <paramref name="x" />.</returns>
/// <remarks>This computes <c>arctan(x)</c> in the interval <c>[-π / 2, +π / 2]</c> radians.</remarks>
static abstract TSelf Atan(TSelf x);

/// <summary>Computes the arc-tangent of the quotient of two values.</summary>
/// <summary>Computes the arc-tangent for the quotient of two values.</summary>
/// <param name="y">The y-coordinate of a point.</param>
/// <param name="x">The x-coordinate of a point.</param>
/// <returns>The arc-tangent of <paramref name="y" /> divided-by <paramref name="x" />.</returns>
/// <remarks>This computes <c>arctan(y / x)</c> in the interval <c>[-π, +π]</c> radians.</remarks>
static abstract TSelf Atan2(TSelf y, TSelf x);

/// <summary>Computes the arc-tangent for the quotient of two values and divides the result by <c>pi</c>.</summary>
/// <param name="y">The y-coordinate of a point.</param>
/// <param name="x">The x-coordinate of a point.</param>
/// <returns>The arc-tangent of <paramref name="y" /> divided-by <paramref name="x" />, divided by <c>pi</c>.</returns>
/// <remarks>This computes <c>arctan(y / x) / π</c> in the interval <c>[-1, +1]</c>.</remarks>
static abstract TSelf Atan2Pi(TSelf y, TSelf x);

/// <summary>Computes the arc-tangent of a value and divides the result by pi.</summary>
/// <param name="x">The value whose arc-tangent is to be computed.</param>
/// <returns>The arc-tangent of <paramref name="x" />, divided by <c>pi</c>.</returns>
/// <remarks>This computes <c>arctan(x) / π</c> in the interval <c>[-0.5, +0.5]</c>.</remarks>
static abstract TSelf AtanPi(TSelf x);

/// <summary>Computes the cosine of a value.</summary>
/// <param name="x">The value, in radians, whose cosine is to be computed.</param>
/// <returns>The cosine of <paramref name="x" />.</returns>
/// <remarks>This computes <c>cos(x)</c>.</remarks>
static abstract TSelf Cos(TSelf x);

/// <summary>Computes the cosine of a value that has been multipled by <c>pi</c>.</summary>
/// <param name="x">The value, in half-revolutions, whose cosine is to be computed.</param>
/// <returns>The cosine of <paramref name="x" /> multiplied-by <c>pi</c>.</returns>
/// <remarks>This computes <c>cos(x * π)</c>.</remarks>
static abstract TSelf CosPi(TSelf x);

/// <summary>Computes the sine of a value.</summary>
/// <param name="x">The value, in radians, whose sine is to be computed.</param>
/// <returns>The sine of <paramref name="x" />.</returns>
/// <remarks>This computes <c>sin(x)</c>.</remarks>
static abstract TSelf Sin(TSelf x);

/// <summary>Computes the sine and cosine of a value.</summary>
/// <param name="x">The value, in radians, whose sine and cosine are to be computed.</param>
/// <returns>The sine and cosine of <paramref name="x" />.</returns>
/// <remarks>This computes <c>(sin(x), cos(x))</c>.</remarks>
static abstract (TSelf Sin, TSelf Cos) SinCos(TSelf x);

/// <summary>Computes the sine of a value that has been multipled by <c>pi</c>.</summary>
/// <param name="x">The value, in half-revolutions, that is multipled by <c>pi</c> before computing its sine.</param>
/// <returns>The sine of <paramref name="x" /> multiplied-by <c>pi</c>.</returns>
/// <remarks>This computes <c>sin(x * π)</c>.</remarks>
static abstract TSelf SinPi(TSelf x);

/// <summary>Computes the tangent of a value.</summary>
/// <param name="x">The value, in radians, whose tangent is to be computed.</param>
/// <returns>The tangent of <paramref name="x" />.</returns>
/// <remarks>This computes <c>tan(x)</c>.</remarks>
static abstract TSelf Tan(TSelf x);

// The following methods are approved but not yet implemented in the libraries
// * static abstract TSelf AcosPi(TSelf x);
// * static abstract TSelf AsinPi(TSelf x);
// * static abstract TSelf AtanPi(TSelf x);
// * static abstract TSelf Atan2Pi(TSelf y, TSelf x);
// * static abstract TSelf CosPi(TSelf x);
// * static abstract TSelf SinPi(TSelf x);
// * static abstract TSelf TanPi(TSelf x);
/// <summary>Computes the tangent of a value that has been multipled by <c>pi</c>.</summary>
/// <param name="x">The value, in half-revolutions, that is multipled by <c>pi</c> before computing its tangent.</param>
/// <returns>The tangent of <paramref name="x" /> multiplied-by <c>pi</c>.</returns>
/// <remarks>This computes <c>tan(x * π)</c>.</remarks>
static abstract TSelf TanPi(TSelf x);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1733,18 +1733,33 @@ private static bool TryConvertTo<TOther>(NFloat value, [NotNullWhen(true)] out T
/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Acos(TSelf)" />
public static NFloat Acos(NFloat x) => new NFloat(NativeType.Acos(x._value));

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.AcosPi(TSelf)" />
public static NFloat AcosPi(NFloat x) => new NFloat(NativeType.AcosPi(x._value));

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Asin(TSelf)" />
public static NFloat Asin(NFloat x) => new NFloat(NativeType.Asin(x._value));

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.AsinPi(TSelf)" />
public static NFloat AsinPi(NFloat x) => new NFloat(NativeType.AsinPi(x._value));

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Atan(TSelf)" />
public static NFloat Atan(NFloat x) => new NFloat(NativeType.Atan(x._value));

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Atan2(TSelf, TSelf)" />
public static NFloat Atan2(NFloat y, NFloat x) => new NFloat(NativeType.Atan2(y._value, x._value));

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Atan2Pi(TSelf, TSelf)" />
public static NFloat Atan2Pi(NFloat y, NFloat x) => new NFloat(NativeType.Atan2Pi(y._value, x._value));

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.AtanPi(TSelf)" />
public static NFloat AtanPi(NFloat x) => new NFloat(NativeType.AtanPi(x._value));

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Cos(TSelf)" />
public static NFloat Cos(NFloat x) => new NFloat(NativeType.Cos(x._value));

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.CosPi(TSelf)" />
public static NFloat CosPi(NFloat x) => new NFloat(NativeType.CosPi(x._value));

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Sin(TSelf)" />
public static NFloat Sin(NFloat x) => new NFloat(NativeType.Sin(x._value));

Expand All @@ -1755,28 +1770,13 @@ public static (NFloat Sin, NFloat Cos) SinCos(NFloat x)
return (new NFloat(sin), new NFloat(cos));
}

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.SinPi(TSelf)" />
public static NFloat SinPi(NFloat x) => new NFloat(NativeType.SinPi(x._value));

/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Tan(TSelf)" />
public static NFloat Tan(NFloat x) => new NFloat(NativeType.Tan(x._value));

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.AcosPi(TSelf)" />
// public static NFloat AcosPi(NFloat x) => new NFloat(NativeType.AcosPi(x._value));

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.AsinPi(TSelf)" />
// public static NFloat AsinPi(NFloat x) => new NFloat(NativeType.AsinPi(x._value));

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.AtanPi(TSelf)" />
// public static NFloat AtanPi(NFloat x) => new NFloat(NativeType.AtanPi(x._value));

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.Atan2Pi(TSelf)" />
// public static NFloat Atan2Pi(NFloat y, NFloat x) => new NFloat(NativeType.Atan2Pi(y._value, x._value));

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.CosPi(TSelf)" />
// public static NFloat CosPi(NFloat x) => new NFloat(NativeType.CosPi(x._value));

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.SinPi(TSelf)" />
// public static NFloat SinPi(NFloat x) => new NFloat(NativeType.SinPi(x._value, y._value));

// /// <inheritdoc cref="ITrigonometricFunctions{TSelf}.TanPi(TSelf)" />
// public static NFloat TanPi(NFloat x) => new NFloat(NativeType.TanPi(x._value, y._value));
/// <inheritdoc cref="ITrigonometricFunctions{TSelf}.TanPi(TSelf)" />
public static NFloat TanPi(NFloat x) => new NFloat(NativeType.TanPi(x._value));
}
}
Loading

0 comments on commit 0855da7

Please sign in to comment.