diff --git a/src/libraries/Common/tests/System/GenericMathTestMemberData.cs b/src/libraries/Common/tests/System/GenericMathTestMemberData.cs index 2e40a0940fc5a..0e19ac826dfdd 100644 --- a/src/libraries/Common/tests/System/GenericMathTestMemberData.cs +++ b/src/libraries/Common/tests/System/GenericMathTestMemberData.cs @@ -198,6 +198,86 @@ public static IEnumerable CopySignSingle } } + public static IEnumerable CosDouble + { + get + { + yield return new object[] { double.NegativeInfinity, double.NaN, 0.0 }; + yield return new object[] { -3.1415926535897932, -1.0, DoubleCrossPlatformMachineEpsilon * 10 }; // value: -(pi) + yield return new object[] { -2.7182818284590452, -0.91173391478696510, DoubleCrossPlatformMachineEpsilon }; // value: -(e) + yield return new object[] { -2.3025850929940457, -0.66820151019031295, DoubleCrossPlatformMachineEpsilon }; // value: -(ln(10)) + yield return new object[] { -1.5707963267948966, 0.0, DoubleCrossPlatformMachineEpsilon }; // value: -(pi / 2) + yield return new object[] { -1.4426950408889634, 0.12775121753523991, DoubleCrossPlatformMachineEpsilon }; // value: -(log2(e)) + yield return new object[] { -1.4142135623730950, 0.15594369476537447, DoubleCrossPlatformMachineEpsilon }; // value: -(sqrt(2)) + yield return new object[] { -1.1283791670955126, 0.42812514788535792, DoubleCrossPlatformMachineEpsilon }; // value: -(2 / sqrt(pi)) + yield return new object[] { -1.0, 0.54030230586813972, DoubleCrossPlatformMachineEpsilon }; + yield return new object[] { -0.78539816339744831, 0.70710678118654752, DoubleCrossPlatformMachineEpsilon }; // value: -(pi / 4), expected: (1 / sqrt(2)) + yield return new object[] { -0.70710678118654752, 0.76024459707563015, DoubleCrossPlatformMachineEpsilon }; // value: -(1 / sqrt(2)) + yield return new object[] { -0.69314718055994531, 0.76923890136397213, DoubleCrossPlatformMachineEpsilon }; // value: -(ln(2)) + yield return new object[] { -0.63661977236758134, 0.80410982822879171, DoubleCrossPlatformMachineEpsilon }; // value: -(2 / pi) + yield return new object[] { -0.43429448190325183, 0.90716712923909839, DoubleCrossPlatformMachineEpsilon }; // value: -(log10(e)) + yield return new object[] { -0.31830988618379067, 0.94976571538163866, DoubleCrossPlatformMachineEpsilon }; // value: -(1 / pi) + yield return new object[] { -0.0, 1.0, DoubleCrossPlatformMachineEpsilon * 10 }; + yield return new object[] { double.NaN, double.NaN, 0.0 }; + yield return new object[] { 0.0, 1.0, DoubleCrossPlatformMachineEpsilon * 10 }; + yield return new object[] { 0.31830988618379067, 0.94976571538163866, DoubleCrossPlatformMachineEpsilon }; // value: (1 / pi) + yield return new object[] { 0.43429448190325183, 0.90716712923909839, DoubleCrossPlatformMachineEpsilon }; // value: (log10(e)) + yield return new object[] { 0.63661977236758134, 0.80410982822879171, DoubleCrossPlatformMachineEpsilon }; // value: (2 / pi) + yield return new object[] { 0.69314718055994531, 0.76923890136397213, DoubleCrossPlatformMachineEpsilon }; // value: (ln(2)) + yield return new object[] { 0.70710678118654752, 0.76024459707563015, DoubleCrossPlatformMachineEpsilon }; // value: (1 / sqrt(2)) + yield return new object[] { 0.78539816339744831, 0.70710678118654752, DoubleCrossPlatformMachineEpsilon }; // value: (pi / 4), expected: (1 / sqrt(2)) + yield return new object[] { 1.0, 0.54030230586813972, DoubleCrossPlatformMachineEpsilon }; + yield return new object[] { 1.1283791670955126, 0.42812514788535792, DoubleCrossPlatformMachineEpsilon }; // value: (2 / sqrt(pi)) + yield return new object[] { 1.4142135623730950, 0.15594369476537447, DoubleCrossPlatformMachineEpsilon }; // value: (sqrt(2)) + yield return new object[] { 1.4426950408889634, 0.12775121753523991, DoubleCrossPlatformMachineEpsilon }; // value: (log2(e)) + yield return new object[] { 1.5707963267948966, 0.0, DoubleCrossPlatformMachineEpsilon }; // value: (pi / 2) + yield return new object[] { 2.3025850929940457, -0.66820151019031295, DoubleCrossPlatformMachineEpsilon }; // value: (ln(10)) + yield return new object[] { 2.7182818284590452, -0.91173391478696510, DoubleCrossPlatformMachineEpsilon }; // value: (e) + yield return new object[] { 3.1415926535897932, -1.0, DoubleCrossPlatformMachineEpsilon * 10 }; // value: (pi) + yield return new object[] { double.PositiveInfinity, double.NaN, 0.0 }; + } + } + + public static IEnumerable CosSingle + { + get + { + yield return new object[] { float.NegativeInfinity, float.NaN, 0.0f }; + yield return new object[] { -3.14159265f, -1.0f, SingleCrossPlatformMachineEpsilon * 10 }; // value: -(pi) + yield return new object[] { -2.71828183f, -0.911733918f, SingleCrossPlatformMachineEpsilon }; // value: -(e) + yield return new object[] { -2.30258509f, -0.668201510f, SingleCrossPlatformMachineEpsilon }; // value: -(ln(10)) + yield return new object[] { -1.57079633f, 0.0f, SingleCrossPlatformMachineEpsilon }; // value: -(pi / 2) + yield return new object[] { -1.44269504f, 0.127751218f, SingleCrossPlatformMachineEpsilon }; // value: -(log2(e)) + yield return new object[] { -1.41421356f, 0.155943695f, SingleCrossPlatformMachineEpsilon }; // value: -(sqrt(2)) + yield return new object[] { -1.12837917f, 0.428125148f, SingleCrossPlatformMachineEpsilon }; // value: -(2 / sqrt(pi)) + yield return new object[] { -1.0f, 0.540302306f, SingleCrossPlatformMachineEpsilon }; + yield return new object[] { -0.785398163f, 0.707106781f, SingleCrossPlatformMachineEpsilon }; // value: -(pi / 4), expected: (1 / sqrt(2)) + yield return new object[] { -0.707106781f, 0.760244597f, SingleCrossPlatformMachineEpsilon }; // value: -(1 / sqrt(2)) + yield return new object[] { -0.693147181f, 0.769238901f, SingleCrossPlatformMachineEpsilon }; // value: -(ln(2)) + yield return new object[] { -0.636619772f, 0.804109828f, SingleCrossPlatformMachineEpsilon }; // value: -(2 / pi) + yield return new object[] { -0.434294482f, 0.907167129f, SingleCrossPlatformMachineEpsilon }; // value: -(log10(e)) + yield return new object[] { -0.318309886f, 0.949765715f, SingleCrossPlatformMachineEpsilon }; // value: -(1 / pi) + yield return new object[] { -0.0f, 1.0f, SingleCrossPlatformMachineEpsilon * 10 }; + yield return new object[] { float.NaN, float.NaN, 0.0f }; + yield return new object[] { 0.0f, 1.0f, SingleCrossPlatformMachineEpsilon * 10 }; + yield return new object[] { 0.318309886f, 0.949765715f, SingleCrossPlatformMachineEpsilon }; // value: (1 / pi) + yield return new object[] { 0.434294482f, 0.907167129f, SingleCrossPlatformMachineEpsilon }; // value: (log10(e)) + yield return new object[] { 0.636619772f, 0.804109828f, SingleCrossPlatformMachineEpsilon }; // value: (2 / pi) + yield return new object[] { 0.693147181f, 0.769238901f, SingleCrossPlatformMachineEpsilon }; // value: (ln(2)) + yield return new object[] { 0.707106781f, 0.760244597f, SingleCrossPlatformMachineEpsilon }; // value: (1 / sqrt(2)) + yield return new object[] { 0.785398163f, 0.707106781f, SingleCrossPlatformMachineEpsilon }; // value: (pi / 4), expected: (1 / sqrt(2)) + yield return new object[] { 1.0f, 0.540302306f, SingleCrossPlatformMachineEpsilon }; + yield return new object[] { 1.12837917f, 0.428125148f, SingleCrossPlatformMachineEpsilon }; // value: (2 / sqrt(pi)) + yield return new object[] { 1.41421356f, 0.155943695f, SingleCrossPlatformMachineEpsilon }; // value: (sqrt(2)) + yield return new object[] { 1.44269504f, 0.127751218f, SingleCrossPlatformMachineEpsilon }; // value: (log2(e)) + yield return new object[] { 1.57079633f, 0.0f, SingleCrossPlatformMachineEpsilon }; // value: (pi / 2) + yield return new object[] { 2.30258509f, -0.668201510f, SingleCrossPlatformMachineEpsilon }; // value: (ln(10)) + yield return new object[] { 2.71828183f, -0.911733918f, SingleCrossPlatformMachineEpsilon }; // value: (e) + yield return new object[] { 3.14159265f, -1.0f, SingleCrossPlatformMachineEpsilon * 10 }; // value: (pi) + yield return new object[] { float.PositiveInfinity, float.NaN, 0.0f }; + } + } + public static IEnumerable DegreesToRadiansDouble { get @@ -981,7 +1061,7 @@ public static IEnumerable Log2Double yield return new object[] { 0.64321824193300488, -0.63661977236758126, DoubleCrossPlatformMachineEpsilon }; // expected: -(2 / pi) yield return new object[] { 0.74005557395545179, -0.43429448190325190, DoubleCrossPlatformMachineEpsilon }; // expected: -(log10(e)) yield return new object[] { 0.80200887896145195, -0.31830988618379073, DoubleCrossPlatformMachineEpsilon }; // expected: -(1 / pi) - yield return new object[] { 1, 0.0, 0.0 }; + yield return new object[] { 1, 0.0, 0.0 }; yield return new object[] { 1.2468689889006383, 0.31830988618379073, DoubleCrossPlatformMachineEpsilon }; // expected: (1 / pi) yield return new object[] { 1.3512498725672678, 0.43429448190325226, DoubleCrossPlatformMachineEpsilon }; // expected: (log10(e)) yield return new object[] { 1.5546822754821001, 0.63661977236758126, DoubleCrossPlatformMachineEpsilon }; // expected: (2 / pi) @@ -1664,6 +1744,170 @@ public static IEnumerable RoundToEvenSingle } } + public static IEnumerable SinDouble + { + get + { + yield return new object[] { double.NegativeInfinity, double.NaN, 0.0 }; + yield return new object[] { -3.1415926535897932, -0.0, DoubleCrossPlatformMachineEpsilon }; // value: -(pi) + yield return new object[] { -2.7182818284590452, -0.41078129050290870, DoubleCrossPlatformMachineEpsilon }; // value: -(e) + yield return new object[] { -2.3025850929940457, -0.74398033695749319, DoubleCrossPlatformMachineEpsilon }; // value: -(ln(10)) + yield return new object[] { -1.5707963267948966, -1.0, DoubleCrossPlatformMachineEpsilon * 10 }; // value: -(pi / 2) + yield return new object[] { -1.4426950408889634, -0.99180624439366372, DoubleCrossPlatformMachineEpsilon }; // value: -(log2(e)) + yield return new object[] { -1.4142135623730950, -0.98776594599273553, DoubleCrossPlatformMachineEpsilon }; // value: -(sqrt(2)) + yield return new object[] { -1.1283791670955126, -0.90371945743584630, DoubleCrossPlatformMachineEpsilon }; // value: -(2 / sqrt(pi)) + yield return new object[] { -1.0, -0.84147098480789651, DoubleCrossPlatformMachineEpsilon }; + yield return new object[] { -0.78539816339744831, -0.70710678118654752, DoubleCrossPlatformMachineEpsilon }; // value: -(pi / 4), expected: -(1 / sqrt(2)) + yield return new object[] { -0.70710678118654752, -0.64963693908006244, DoubleCrossPlatformMachineEpsilon }; // value: -(1 / sqrt(2)) + yield return new object[] { -0.69314718055994531, -0.63896127631363480, DoubleCrossPlatformMachineEpsilon }; // value: -(ln(2)) + yield return new object[] { -0.63661977236758134, -0.59448076852482208, DoubleCrossPlatformMachineEpsilon }; // value: -(2 / pi) + yield return new object[] { -0.43429448190325183, -0.42077048331375735, DoubleCrossPlatformMachineEpsilon }; // value: -(log10(e)) + yield return new object[] { -0.31830988618379067, -0.31296179620778659, DoubleCrossPlatformMachineEpsilon }; // value: -(1 / pi) + yield return new object[] { -0.0, -0.0, 0.0 }; + yield return new object[] { double.NaN, double.NaN, 0.0 }; + yield return new object[] { 0.0, 0.0, 0.0 }; + yield return new object[] { 0.31830988618379067, 0.31296179620778659, DoubleCrossPlatformMachineEpsilon }; // value: (1 / pi) + yield return new object[] { 0.43429448190325183, 0.42077048331375735, DoubleCrossPlatformMachineEpsilon }; // value: (log10(e)) + yield return new object[] { 0.63661977236758134, 0.59448076852482208, DoubleCrossPlatformMachineEpsilon }; // value: (2 / pi) + yield return new object[] { 0.69314718055994531, 0.63896127631363480, DoubleCrossPlatformMachineEpsilon }; // value: (ln(2)) + yield return new object[] { 0.70710678118654752, 0.64963693908006244, DoubleCrossPlatformMachineEpsilon }; // value: (1 / sqrt(2)) + yield return new object[] { 0.78539816339744831, 0.70710678118654752, DoubleCrossPlatformMachineEpsilon }; // value: (pi / 4), expected: (1 / sqrt(2)) + yield return new object[] { 1.0, 0.84147098480789651, DoubleCrossPlatformMachineEpsilon }; + yield return new object[] { 1.1283791670955126, 0.90371945743584630, DoubleCrossPlatformMachineEpsilon }; // value: (2 / sqrt(pi)) + yield return new object[] { 1.4142135623730950, 0.98776594599273553, DoubleCrossPlatformMachineEpsilon }; // value: (sqrt(2)) + yield return new object[] { 1.4426950408889634, 0.99180624439366372, DoubleCrossPlatformMachineEpsilon }; // value: (log2(e)) + yield return new object[] { 1.5707963267948966, 1.0, DoubleCrossPlatformMachineEpsilon * 10 }; // value: (pi / 2) + yield return new object[] { 2.3025850929940457, 0.74398033695749319, DoubleCrossPlatformMachineEpsilon }; // value: (ln(10)) + yield return new object[] { 2.7182818284590452, 0.41078129050290870, DoubleCrossPlatformMachineEpsilon }; // value: (e) + yield return new object[] { 3.1415926535897932, 0.0, DoubleCrossPlatformMachineEpsilon }; // value: (pi) + yield return new object[] { double.PositiveInfinity, double.NaN, 0.0 }; + } + } + + public static IEnumerable SinSingle + { + get + { + yield return new object[] { float.NegativeInfinity, float.NaN, 0.0f }; + yield return new object[] { -3.14159265f, -0.0f, SingleCrossPlatformMachineEpsilon }; // value: -(pi) + yield return new object[] { -2.71828183f, -0.410781291f, SingleCrossPlatformMachineEpsilon }; // value: -(e) + yield return new object[] { -2.30258509f, -0.743980337f, SingleCrossPlatformMachineEpsilon }; // value: -(ln(10)) + yield return new object[] { -1.57079633f, -1.0f, SingleCrossPlatformMachineEpsilon * 10 }; // value: -(pi / 2) + yield return new object[] { -1.44269504f, -0.991806244f, SingleCrossPlatformMachineEpsilon }; // value: -(log2(e)) + yield return new object[] { -1.41421356f, -0.987765946f, SingleCrossPlatformMachineEpsilon }; // value: -(sqrt(2)) + yield return new object[] { -1.12837917f, -0.903719457f, SingleCrossPlatformMachineEpsilon }; // value: -(2 / sqrt(pi)) + yield return new object[] { -1.0f, -0.841470985f, SingleCrossPlatformMachineEpsilon }; + yield return new object[] { -0.785398163f, -0.707106781f, SingleCrossPlatformMachineEpsilon }; // value: -(pi / 4), expected: -(1 / sqrt(2)) + yield return new object[] { -0.707106781f, -0.649636939f, SingleCrossPlatformMachineEpsilon }; // value: -(1 / sqrt(2)) + yield return new object[] { -0.693147181f, -0.638961276f, SingleCrossPlatformMachineEpsilon }; // value: -(ln(2)) + yield return new object[] { -0.636619772f, -0.594480769f, SingleCrossPlatformMachineEpsilon }; // value: -(2 / pi) + yield return new object[] { -0.434294482f, -0.420770483f, SingleCrossPlatformMachineEpsilon }; // value: -(log10(e)) + yield return new object[] { -0.318309886f, -0.312961796f, SingleCrossPlatformMachineEpsilon }; // value: -(1 / pi) + yield return new object[] { -0.0f, -0.0f, 0.0f }; + yield return new object[] { float.NaN, float.NaN, 0.0f }; + yield return new object[] { 0.0f, 0.0f, 0.0f }; + yield return new object[] { 0.318309886f, 0.312961796f, SingleCrossPlatformMachineEpsilon }; // value: (1 / pi) + yield return new object[] { 0.434294482f, 0.420770483f, SingleCrossPlatformMachineEpsilon }; // value: (log10(e)) + yield return new object[] { 0.636619772f, 0.594480769f, SingleCrossPlatformMachineEpsilon }; // value: (2 / pi) + yield return new object[] { 0.693147181f, 0.638961276f, SingleCrossPlatformMachineEpsilon }; // value: (ln(2)) + yield return new object[] { 0.707106781f, 0.649636939f, SingleCrossPlatformMachineEpsilon }; // value: (1 / sqrt(2)) + yield return new object[] { 0.785398163f, 0.707106781f, SingleCrossPlatformMachineEpsilon }; // value: (pi / 4), expected: (1 / sqrt(2)) + yield return new object[] { 1.0f, 0.841470985f, SingleCrossPlatformMachineEpsilon }; + yield return new object[] { 1.12837917f, 0.903719457f, SingleCrossPlatformMachineEpsilon }; // value: (2 / sqrt(pi)) + yield return new object[] { 1.41421356f, 0.987765946f, SingleCrossPlatformMachineEpsilon }; // value: (sqrt(2)) + yield return new object[] { 1.44269504f, 0.991806244f, SingleCrossPlatformMachineEpsilon }; // value: (log2(e)) + yield return new object[] { 1.57079633f, 1.0f, SingleCrossPlatformMachineEpsilon * 10 }; // value: (pi / 2) + yield return new object[] { 2.30258509f, 0.743980337f, SingleCrossPlatformMachineEpsilon }; // value: (ln(10)) + yield return new object[] { 2.71828183f, 0.410781291f, SingleCrossPlatformMachineEpsilon }; // value: (e) + yield return new object[] { 3.14159265f, 0.0f, SingleCrossPlatformMachineEpsilon }; // value: (pi) + yield return new object[] { float.PositiveInfinity, float.NaN, 0.0f }; + } + } + + public static IEnumerable SinCosDouble + { + get + { + yield return new object[] { double.NegativeInfinity, double.NaN, double.NaN, 0.0, 0.0 }; + yield return new object[] { -1e18, 0.9929693207404051, 0.11837199021871073, 0.0002, 0.002 }; // https://github.com/dotnet/runtime/issues/98204 + yield return new object[] { -3.1415926535897932, -0.0, -1.0, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon * 10 }; // value: -(pi) + yield return new object[] { -2.7182818284590452, -0.41078129050290870, -0.91173391478696510, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: -(e) + yield return new object[] { -2.3025850929940457, -0.74398033695749319, -0.66820151019031295, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: -(ln(10)) + yield return new object[] { -1.5707963267948966, -1.0, 0.0, DoubleCrossPlatformMachineEpsilon * 10, DoubleCrossPlatformMachineEpsilon }; // value: -(pi / 2) + yield return new object[] { -1.4426950408889634, -0.99180624439366372, 0.12775121753523991, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: -(log2(e)) + yield return new object[] { -1.4142135623730950, -0.98776594599273553, 0.15594369476537447, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: -(sqrt(2)) + yield return new object[] { -1.1283791670955126, -0.90371945743584630, 0.42812514788535792, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: -(2 / sqrt(pi)) + yield return new object[] { -1.0, -0.84147098480789651, 0.54030230586813972, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; + yield return new object[] { -0.78539816339744831, -0.70710678118654752, 0.70710678118654752, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: -(pi / 4), expected_sin: -(1 / sqrt(2)), expected_cos: 1 + yield return new object[] { -0.70710678118654752, -0.64963693908006244, 0.76024459707563015, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: -(1 / sqrt(2)) + yield return new object[] { -0.69314718055994531, -0.63896127631363480, 0.76923890136397213, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: -(ln(2)) + yield return new object[] { -0.63661977236758134, -0.59448076852482208, 0.80410982822879171, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: -(2 / pi) + yield return new object[] { -0.43429448190325183, -0.42077048331375735, 0.90716712923909839, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: -(log10(e)) + yield return new object[] { -0.31830988618379067, -0.31296179620778659, 0.94976571538163866, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: -(1 / pi) + yield return new object[] { -0.0, -0.0, 1.0, 0.0, DoubleCrossPlatformMachineEpsilon * 10 }; + yield return new object[] { double.NaN, double.NaN, double.NaN, 0.0, 0.0 }; + yield return new object[] { 0.0, 0.0, 1.0, 0.0, DoubleCrossPlatformMachineEpsilon * 10 }; + yield return new object[] { 0.31830988618379067, 0.31296179620778659, 0.94976571538163866, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: (1 / pi) + yield return new object[] { 0.43429448190325183, 0.42077048331375735, 0.90716712923909839, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: (log10(e)) + yield return new object[] { 0.63661977236758134, 0.59448076852482208, 0.80410982822879171, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: (2 / pi) + yield return new object[] { 0.69314718055994531, 0.63896127631363480, 0.76923890136397213, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: (ln(2)) + yield return new object[] { 0.70710678118654752, 0.64963693908006244, 0.76024459707563015, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: (1 / sqrt(2)) + yield return new object[] { 0.78539816339744831, 0.70710678118654752, 0.70710678118654752, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: (pi / 4), expected_sin: (1 / sqrt(2)), expected_cos: 1 + yield return new object[] { 1.0, 0.84147098480789651, 0.54030230586813972, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; + yield return new object[] { 1.1283791670955126, 0.90371945743584630, 0.42812514788535792, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: (2 / sqrt(pi)) + yield return new object[] { 1.4142135623730950, 0.98776594599273553, 0.15594369476537447, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: (sqrt(2)) + yield return new object[] { 1.4426950408889634, 0.99180624439366372, 0.12775121753523991, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: (log2(e)) + yield return new object[] { 1.5707963267948966, 1.0, 0.0, DoubleCrossPlatformMachineEpsilon * 10, DoubleCrossPlatformMachineEpsilon }; // value: (pi / 2) + yield return new object[] { 2.3025850929940457, 0.74398033695749319, -0.66820151019031295, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: (ln(10)) + yield return new object[] { 2.7182818284590452, 0.41078129050290870, -0.91173391478696510, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon }; // value: (e) + yield return new object[] { 3.1415926535897932, 0.0, -1.0, DoubleCrossPlatformMachineEpsilon, DoubleCrossPlatformMachineEpsilon * 10 }; // value: (pi) + yield return new object[] { 1e18, -0.9929693207404051, 0.11837199021871073, 0.0002, 0.002 }; // https://github.com/dotnet/runtime/issues/98204 + yield return new object[] { double.PositiveInfinity, double.NaN, double.NaN, 0.0, 0.0 }; + } + } + + public static IEnumerable SinCosSingle + { + get + { + yield return new object[] { float.NegativeInfinity, float.NaN, float.NaN, 0.0f, 0.0f }; + yield return new object[] { -1e8f, -0.931639, -0.36338508, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // https://github.com/dotnet/runtime/issues/98204 + yield return new object[] { -3.14159265f, -0.0f, -1.0f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon * 10 }; // value: -(pi) + yield return new object[] { -2.71828183f, -0.410781291f, -0.911733918f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: -(e) + yield return new object[] { -2.30258509f, -0.743980337f, -0.668201510f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: -(ln(10)) + yield return new object[] { -1.57079633f, -1.0f, 0.0f, SingleCrossPlatformMachineEpsilon * 10, SingleCrossPlatformMachineEpsilon }; // value: -(pi / 2) + yield return new object[] { -1.44269504f, -0.991806244f, 0.127751218f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: -(log2(e)) + yield return new object[] { -1.41421356f, -0.987765946f, 0.155943695f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: -(sqrt(2)) + yield return new object[] { -1.12837917f, -0.903719457f, 0.428125148f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: -(2 / sqrt(pi)) + yield return new object[] { -1.0f, -0.841470985f, 0.540302306f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; + yield return new object[] { -0.785398163f, -0.707106781f, 0.707106781f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: -(pi / 4), expected_sin: -(1 / sqrt(2)), expected_cos: 1 + yield return new object[] { -0.707106781f, -0.649636939f, 0.760244597f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: -(1 / sqrt(2)) + yield return new object[] { -0.693147181f, -0.638961276f, 0.769238901f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: -(ln(2)) + yield return new object[] { -0.636619772f, -0.594480769f, 0.804109828f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: -(2 / pi) + yield return new object[] { -0.434294482f, -0.420770483f, 0.907167129f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: -(log10(e)) + yield return new object[] { -0.318309886f, -0.312961796f, 0.949765715f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: -(1 / pi) + yield return new object[] { -0.0f, -0.0f, 1.0f, 0.0f, SingleCrossPlatformMachineEpsilon * 10 }; + yield return new object[] { float.NaN, float.NaN, float.NaN, 0.0f, 0.0f }; + yield return new object[] { 0.0f, 0.0f, 1.0f, 0.0f, SingleCrossPlatformMachineEpsilon * 10 }; + yield return new object[] { 0.318309886f, 0.312961796f, 0.949765715f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: (1 / pi) + yield return new object[] { 0.434294482f, 0.420770483f, 0.907167129f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: (log10(e)) + yield return new object[] { 0.636619772f, 0.594480769f, 0.804109828f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: (2 / pi) + yield return new object[] { 0.693147181f, 0.638961276f, 0.769238901f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: (ln(2)) + yield return new object[] { 0.707106781f, 0.649636939f, 0.760244597f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: (1 / sqrt(2)) + yield return new object[] { 0.785398163f, 0.707106781f, 0.707106781f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: (pi / 4), expected_sin: (1 / sqrt(2)), expected_cos: 1 + yield return new object[] { 1.0f, 0.841470985f, 0.540302306f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; + yield return new object[] { 1.12837917f, 0.903719457f, 0.428125148f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: (2 / sqrt(pi)) + yield return new object[] { 1.41421356f, 0.987765946f, 0.155943695f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: (sqrt(2)) + yield return new object[] { 1.44269504f, 0.991806244f, 0.127751218f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: (log2(e)) + yield return new object[] { 1.57079633f, 1.0f, 0.0f, SingleCrossPlatformMachineEpsilon * 10, SingleCrossPlatformMachineEpsilon }; // value: (pi / 2) + yield return new object[] { 2.30258509f, 0.743980337f, -0.668201510f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: (ln(10)) + yield return new object[] { 2.71828183f, 0.410781291f, -0.911733918f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // value: (e) + yield return new object[] { 3.14159265f, 0.0f, -1.0f, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon * 10 }; // value: (pi) + yield return new object[] { 1e8f, 0.931639, -0.36338508, SingleCrossPlatformMachineEpsilon, SingleCrossPlatformMachineEpsilon }; // https://github.com/dotnet/runtime/issues/98204 + yield return new object[] { float.PositiveInfinity, float.NaN, float.NaN, 0.0f, 0.0f }; + } + } + public static IEnumerable TruncateDouble { get diff --git a/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs b/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs index 8caf901a258be..14b1a2ec62833 100644 --- a/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs @@ -4536,6 +4536,22 @@ private static void TestCreateSequence(T start, T step) } } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosDouble), MemberType = typeof(GenericMathTestMemberData))] + public void CosDoubleTest(double value, double expectedResult, double variance) + { + Vector actualResult = Vector.Cos(Vector.Create(value)); + AssertEqual(Vector.Create(expectedResult), actualResult, Vector.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void CosCosgleTest(float value, float expectedResult, float variance) + { + Vector actualResult = Vector.Cos(Vector.Create(value)); + AssertEqual(Vector.Create(expectedResult), actualResult, Vector.Create(variance)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.ExpDouble), MemberType = typeof(GenericMathTestMemberData))] public void ExpDoubleTest(double value, double expectedResult, double variance) @@ -4959,6 +4975,40 @@ public void RoundToEvenSingleTest(float value, float expectedResult) AssertEqual(Vector.Create(expectedResult), actualResult, Vector.Zero); } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinDouble), MemberType = typeof(GenericMathTestMemberData))] + public void SinDoubleTest(double value, double expectedResult, double variance) + { + Vector actualResult = Vector.Sin(Vector.Create(value)); + AssertEqual(Vector.Create(expectedResult), actualResult, Vector.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinSingleTest(float value, float expectedResult, float variance) + { + Vector actualResult = Vector.Sin(Vector.Create(value)); + AssertEqual(Vector.Create(expectedResult), actualResult, Vector.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosDouble), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosDoubleTest(double value, double expectedResultSin, double expectedResultCos, double allowedVarianceSin, double allowedVarianceCos) + { + (Vector resultSin, Vector resultCos) = Vector.SinCos(Vector.Create(value)); + AssertEqual(Vector.Create(expectedResultSin), resultSin, Vector.Create(allowedVarianceSin)); + AssertEqual(Vector.Create(expectedResultCos), resultCos, Vector.Create(allowedVarianceCos)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos) + { + (Vector resultSin, Vector resultCos) = Vector.SinCos(Vector.Create(value)); + AssertEqual(Vector.Create(expectedResultSin), resultSin, Vector.Create(allowedVarianceSin)); + AssertEqual(Vector.Create(expectedResultCos), resultCos, Vector.Create(allowedVarianceCos)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.TruncateDouble), MemberType = typeof(GenericMathTestMemberData))] public void TruncateDoubleTest(double value, double expectedResult) diff --git a/src/libraries/System.Numerics.Vectors/tests/Vector2Tests.cs b/src/libraries/System.Numerics.Vectors/tests/Vector2Tests.cs index 3d130d2655609..f2b4a61bbd9bc 100644 --- a/src/libraries/System.Numerics.Vectors/tests/Vector2Tests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/Vector2Tests.cs @@ -1299,6 +1299,14 @@ private class EmbeddedVectorObject public Vector2 FieldVector; } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void CosSingleTest(float value, float expectedResult, float variance) + { + Vector2 actualResult = Vector2.Cos(Vector2.Create(value)); + AssertEqual(Vector2.Create(expectedResult), actualResult, Vector2.Create(variance)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.ExpSingle), MemberType = typeof(GenericMathTestMemberData))] public void ExpSingleTest(float value, float expectedResult, float variance) @@ -1474,6 +1482,23 @@ public void RoundToEvenSingleTest(float value, float expectedResult) AssertEqual(Vector2.Create(expectedResult), actualResult, Vector2.Zero); } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinSingleTest(float value, float expectedResult, float variance) + { + Vector2 actualResult = Vector2.Sin(Vector2.Create(value)); + AssertEqual(Vector2.Create(expectedResult), actualResult, Vector2.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos) + { + (Vector2 resultSin, Vector2 resultCos) = Vector2.SinCos(Vector2.Create(value)); + AssertEqual(Vector2.Create(expectedResultSin), resultSin, Vector2.Create(allowedVarianceSin)); + AssertEqual(Vector2.Create(expectedResultCos), resultCos, Vector2.Create(allowedVarianceCos)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.TruncateSingle), MemberType = typeof(GenericMathTestMemberData))] public void TruncateSingleTest(float value, float expectedResult) diff --git a/src/libraries/System.Numerics.Vectors/tests/Vector3Tests.cs b/src/libraries/System.Numerics.Vectors/tests/Vector3Tests.cs index 9ec5e50423938..210caf826fb10 100644 --- a/src/libraries/System.Numerics.Vectors/tests/Vector3Tests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/Vector3Tests.cs @@ -1349,6 +1349,14 @@ private class EmbeddedVectorObject public Vector3 FieldVector; } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void CosSingleTest(float value, float expectedResult, float variance) + { + Vector3 actualResult = Vector3.Cos(Vector3.Create(value)); + AssertEqual(Vector3.Create(expectedResult), actualResult, Vector3.Create(variance)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.ExpSingle), MemberType = typeof(GenericMathTestMemberData))] public void ExpSingleTest(float value, float expectedResult, float variance) @@ -1524,6 +1532,23 @@ public void RoundToEvenSingleTest(float value, float expectedResult) AssertEqual(Vector3.Create(expectedResult), actualResult, Vector3.Zero); } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinSingleTest(float value, float expectedResult, float variance) + { + Vector3 actualResult = Vector3.Sin(Vector3.Create(value)); + AssertEqual(Vector3.Create(expectedResult), actualResult, Vector3.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos) + { + (Vector3 resultSin, Vector3 resultCos) = Vector3.SinCos(Vector3.Create(value)); + AssertEqual(Vector3.Create(expectedResultSin), resultSin, Vector3.Create(allowedVarianceSin)); + AssertEqual(Vector3.Create(expectedResultCos), resultCos, Vector3.Create(allowedVarianceCos)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.TruncateSingle), MemberType = typeof(GenericMathTestMemberData))] public void TruncateSingleTest(float value, float expectedResult) diff --git a/src/libraries/System.Numerics.Vectors/tests/Vector4Tests.cs b/src/libraries/System.Numerics.Vectors/tests/Vector4Tests.cs index d1144cdf3e5cd..74ffeeba94c56 100644 --- a/src/libraries/System.Numerics.Vectors/tests/Vector4Tests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/Vector4Tests.cs @@ -1724,6 +1724,14 @@ public struct Level7 } #pragma warning restore 0169 + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void CosSingleTest(float value, float expectedResult, float variance) + { + Vector4 actualResult = Vector4.Cos(Vector4.Create(value)); + AssertEqual(Vector4.Create(expectedResult), actualResult, Vector4.Create(variance)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.ExpSingle), MemberType = typeof(GenericMathTestMemberData))] public void ExpSingleTest(float value, float expectedResult, float variance) @@ -1899,6 +1907,23 @@ public void RoundToEvenSingleTest(float value, float expectedResult) AssertEqual(Vector4.Create(expectedResult), actualResult, Vector4.Zero); } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinSingleTest(float value, float expectedResult, float variance) + { + Vector4 actualResult = Vector4.Sin(Vector4.Create(value)); + AssertEqual(Vector4.Create(expectedResult), actualResult, Vector4.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos) + { + (Vector4 resultSin, Vector4 resultCos) = Vector4.SinCos(Vector4.Create(value)); + AssertEqual(Vector4.Create(expectedResultSin), resultSin, Vector4.Create(allowedVarianceSin)); + AssertEqual(Vector4.Create(expectedResultCos), resultCos, Vector4.Create(allowedVarianceCos)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.TruncateSingle), MemberType = typeof(GenericMathTestMemberData))] public void TruncateSingleTest(float value, float expectedResult) diff --git a/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector128Tests.cs b/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector128Tests.cs index 5c32e8b991e7e..27955248daac8 100644 --- a/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector128Tests.cs +++ b/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector128Tests.cs @@ -4824,6 +4824,22 @@ private static void TestCreateSequence(T start, T step) } } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosDouble), MemberType = typeof(GenericMathTestMemberData))] + public void CosDoubleTest(double value, double expectedResult, double variance) + { + Vector128 actualResult = Vector128.Cos(Vector128.Create(value)); + AssertEqual(Vector128.Create(expectedResult), actualResult, Vector128.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void CosSingleTest(float value, float expectedResult, float variance) + { + Vector128 actualResult = Vector128.Cos(Vector128.Create(value)); + AssertEqual(Vector128.Create(expectedResult), actualResult, Vector128.Create(variance)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.ExpDouble), MemberType = typeof(GenericMathTestMemberData))] public void ExpDoubleTest(double value, double expectedResult, double variance) @@ -5329,6 +5345,40 @@ public void RoundToEvenSingleTest(float value, float expectedResult) AssertEqual(Vector128.Create(expectedResult), actualResult, Vector128.Zero); } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinDouble), MemberType = typeof(GenericMathTestMemberData))] + public void SinDoubleTest(double value, double expectedResult, double variance) + { + Vector128 actualResult = Vector128.Sin(Vector128.Create(value)); + AssertEqual(Vector128.Create(expectedResult), actualResult, Vector128.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinSingleTest(float value, float expectedResult, float variance) + { + Vector128 actualResult = Vector128.Sin(Vector128.Create(value)); + AssertEqual(Vector128.Create(expectedResult), actualResult, Vector128.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosDouble), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosDoubleTest(double value, double expectedResultSin, double expectedResultCos, double allowedVarianceSin, double allowedVarianceCos) + { + (Vector128 resultSin, Vector128 resultCos) = Vector128.SinCos(Vector128.Create(value)); + AssertEqual(Vector128.Create(expectedResultSin), resultSin, Vector128.Create(allowedVarianceSin)); + AssertEqual(Vector128.Create(expectedResultCos), resultCos, Vector128.Create(allowedVarianceCos)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos) + { + (Vector128 resultSin, Vector128 resultCos) = Vector128.SinCos(Vector128.Create(value)); + AssertEqual(Vector128.Create(expectedResultSin), resultSin, Vector128.Create(allowedVarianceSin)); + AssertEqual(Vector128.Create(expectedResultCos), resultCos, Vector128.Create(allowedVarianceCos)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.TruncateDouble), MemberType = typeof(GenericMathTestMemberData))] public void TruncateDoubleTest(double value, double expectedResult) diff --git a/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector256Tests.cs b/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector256Tests.cs index 0c5cd3bdb2e82..d16e5eed48180 100644 --- a/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector256Tests.cs +++ b/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector256Tests.cs @@ -5840,6 +5840,22 @@ private static void TestCreateSequence(T start, T step) } } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosDouble), MemberType = typeof(GenericMathTestMemberData))] + public void CosDoubleTest(double value, double expectedResult, double variance) + { + Vector256 actualResult = Vector256.Cos(Vector256.Create(value)); + AssertEqual(Vector256.Create(expectedResult), actualResult, Vector256.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void CosSingleTest(float value, float expectedResult, float variance) + { + Vector256 actualResult = Vector256.Cos(Vector256.Create(value)); + AssertEqual(Vector256.Create(expectedResult), actualResult, Vector256.Create(variance)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.ExpDouble), MemberType = typeof(GenericMathTestMemberData))] public void ExpDoubleTest(double value, double expectedResult, double variance) @@ -6345,6 +6361,40 @@ public void RoundToEvenSingleTest(float value, float expectedResult) AssertEqual(Vector256.Create(expectedResult), actualResult, Vector256.Zero); } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinDouble), MemberType = typeof(GenericMathTestMemberData))] + public void SinDoubleTest(double value, double expectedResult, double variance) + { + Vector256 actualResult = Vector256.Sin(Vector256.Create(value)); + AssertEqual(Vector256.Create(expectedResult), actualResult, Vector256.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinSingleTest(float value, float expectedResult, float variance) + { + Vector256 actualResult = Vector256.Sin(Vector256.Create(value)); + AssertEqual(Vector256.Create(expectedResult), actualResult, Vector256.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosDouble), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosDoubleTest(double value, double expectedResultSin, double expectedResultCos, double allowedVarianceSin, double allowedVarianceCos) + { + (Vector256 resultSin, Vector256 resultCos) = Vector256.SinCos(Vector256.Create(value)); + AssertEqual(Vector256.Create(expectedResultSin), resultSin, Vector256.Create(allowedVarianceSin)); + AssertEqual(Vector256.Create(expectedResultCos), resultCos, Vector256.Create(allowedVarianceCos)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos) + { + (Vector256 resultSin, Vector256 resultCos) = Vector256.SinCos(Vector256.Create(value)); + AssertEqual(Vector256.Create(expectedResultSin), resultSin, Vector256.Create(allowedVarianceSin)); + AssertEqual(Vector256.Create(expectedResultCos), resultCos, Vector256.Create(allowedVarianceCos)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.TruncateDouble), MemberType = typeof(GenericMathTestMemberData))] public void TruncateDoubleTest(double value, double expectedResult) diff --git a/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector512Tests.cs b/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector512Tests.cs index 450abc7f32b86..f996d82369615 100644 --- a/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector512Tests.cs +++ b/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector512Tests.cs @@ -5273,6 +5273,22 @@ private static void TestCreateSequence(T start, T step) } } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosDouble), MemberType = typeof(GenericMathTestMemberData))] + public void CosDoubleTest(double value, double expectedResult, double variance) + { + Vector512 actualResult = Vector512.Cos(Vector512.Create(value)); + AssertEqual(Vector512.Create(expectedResult), actualResult, Vector512.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void CosSingleTest(float value, float expectedResult, float variance) + { + Vector512 actualResult = Vector512.Cos(Vector512.Create(value)); + AssertEqual(Vector512.Create(expectedResult), actualResult, Vector512.Create(variance)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.ExpDouble), MemberType = typeof(GenericMathTestMemberData))] public void ExpDoubleTest(double value, double expectedResult, double variance) @@ -5778,6 +5794,40 @@ public void RoundToEvenSingleTest(float value, float expectedResult) AssertEqual(Vector512.Create(expectedResult), actualResult, Vector512.Zero); } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinDouble), MemberType = typeof(GenericMathTestMemberData))] + public void SinDoubleTest(double value, double expectedResult, double variance) + { + Vector512 actualResult = Vector512.Sin(Vector512.Create(value)); + AssertEqual(Vector512.Create(expectedResult), actualResult, Vector512.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinSingleTest(float value, float expectedResult, float variance) + { + Vector512 actualResult = Vector512.Sin(Vector512.Create(value)); + AssertEqual(Vector512.Create(expectedResult), actualResult, Vector512.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosDouble), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosDoubleTest(double value, double expectedResultSin, double expectedResultCos, double allowedVarianceSin, double allowedVarianceCos) + { + (Vector512 resultSin, Vector512 resultCos) = Vector512.SinCos(Vector512.Create(value)); + AssertEqual(Vector512.Create(expectedResultSin), resultSin, Vector512.Create(allowedVarianceSin)); + AssertEqual(Vector512.Create(expectedResultCos), resultCos, Vector512.Create(allowedVarianceCos)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos) + { + (Vector512 resultSin, Vector512 resultCos) = Vector512.SinCos(Vector512.Create(value)); + AssertEqual(Vector512.Create(expectedResultSin), resultSin, Vector512.Create(allowedVarianceSin)); + AssertEqual(Vector512.Create(expectedResultCos), resultCos, Vector512.Create(allowedVarianceCos)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.TruncateDouble), MemberType = typeof(GenericMathTestMemberData))] public void TruncateDoubleTest(double value, double expectedResult) diff --git a/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector64Tests.cs b/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector64Tests.cs index ba7ee7c891787..c049c08515a08 100644 --- a/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector64Tests.cs +++ b/src/libraries/System.Runtime.Intrinsics/tests/Vectors/Vector64Tests.cs @@ -4241,6 +4241,22 @@ private static void TestCreateSequence(T start, T step) } } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosDouble), MemberType = typeof(GenericMathTestMemberData))] + public void CosDoubleTest(double value, double expectedResult, double variance) + { + Vector64 actualResult = Vector64.Cos(Vector64.Create(value)); + AssertEqual(Vector64.Create(expectedResult), actualResult, Vector64.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void CosSingleTest(float value, float expectedResult, float variance) + { + Vector64 actualResult = Vector64.Cos(Vector64.Create(value)); + AssertEqual(Vector64.Create(expectedResult), actualResult, Vector64.Create(variance)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.ExpDouble), MemberType = typeof(GenericMathTestMemberData))] public void ExpDoubleTest(double value, double expectedResult, double variance) @@ -4736,6 +4752,40 @@ public void RoundToEvenSingleTest(float value, float expectedResult) AssertEqual(Vector64.Create(expectedResult), actualResult, Vector64.Zero); } + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinDouble), MemberType = typeof(GenericMathTestMemberData))] + public void SinDoubleTest(double value, double expectedResult, double variance) + { + Vector64 actualResult = Vector64.Sin(Vector64.Create(value)); + AssertEqual(Vector64.Create(expectedResult), actualResult, Vector64.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinSingleTest(float value, float expectedResult, float variance) + { + Vector64 actualResult = Vector64.Sin(Vector64.Create(value)); + AssertEqual(Vector64.Create(expectedResult), actualResult, Vector64.Create(variance)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosDouble), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosDoubleTest(double value, double expectedResultSin, double expectedResultCos, double allowedVarianceSin, double allowedVarianceCos) + { + (Vector64 resultSin, Vector64 resultCos) = Vector64.SinCos(Vector64.Create(value)); + AssertEqual(Vector64.Create(expectedResultSin), resultSin, Vector64.Create(allowedVarianceSin)); + AssertEqual(Vector64.Create(expectedResultCos), resultCos, Vector64.Create(allowedVarianceCos)); + } + + [Theory] + [MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))] + public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos) + { + (Vector64 resultSin, Vector64 resultCos) = Vector64.SinCos(Vector64.Create(value)); + AssertEqual(Vector64.Create(expectedResultSin), resultSin, Vector64.Create(allowedVarianceSin)); + AssertEqual(Vector64.Create(expectedResultCos), resultCos, Vector64.Create(allowedVarianceCos)); + } + [Theory] [MemberData(nameof(GenericMathTestMemberData.TruncateDouble), MemberType = typeof(GenericMathTestMemberData))] public void TruncateDoubleTest(double value, double expectedResult) diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Math.cs b/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Math.cs index 136e4acf1d373..2550b706b4106 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Math.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/Math.cs @@ -473,39 +473,7 @@ public static void Ceiling_Double_IEEE(double value, double expectedResult, doub } [Theory] - [InlineData( double.NegativeInfinity, double.NaN, 0.0)] - [InlineData(-3.1415926535897932, -1.0, CrossPlatformMachineEpsilon * 10)] // value: -(pi) - [InlineData(-2.7182818284590452, -0.91173391478696510, CrossPlatformMachineEpsilon)] // value: -(e) - [InlineData(-2.3025850929940457, -0.66820151019031295, CrossPlatformMachineEpsilon)] // value: -(ln(10)) - [InlineData(-1.5707963267948966, 0.0, CrossPlatformMachineEpsilon)] // value: -(pi / 2) - [InlineData(-1.4426950408889634, 0.12775121753523991, CrossPlatformMachineEpsilon)] // value: -(log2(e)) - [InlineData(-1.4142135623730950, 0.15594369476537447, CrossPlatformMachineEpsilon)] // value: -(sqrt(2)) - [InlineData(-1.1283791670955126, 0.42812514788535792, CrossPlatformMachineEpsilon)] // value: -(2 / sqrt(pi)) - [InlineData(-1.0, 0.54030230586813972, CrossPlatformMachineEpsilon)] - [InlineData(-0.78539816339744831, 0.70710678118654752, CrossPlatformMachineEpsilon)] // value: -(pi / 4), expected: (1 / sqrt(2)) - [InlineData(-0.70710678118654752, 0.76024459707563015, CrossPlatformMachineEpsilon)] // value: -(1 / sqrt(2)) - [InlineData(-0.69314718055994531, 0.76923890136397213, CrossPlatformMachineEpsilon)] // value: -(ln(2)) - [InlineData(-0.63661977236758134, 0.80410982822879171, CrossPlatformMachineEpsilon)] // value: -(2 / pi) - [InlineData(-0.43429448190325183, 0.90716712923909839, CrossPlatformMachineEpsilon)] // value: -(log10(e)) - [InlineData(-0.31830988618379067, 0.94976571538163866, CrossPlatformMachineEpsilon)] // value: -(1 / pi) - [InlineData(-0.0, 1.0, CrossPlatformMachineEpsilon * 10)] - [InlineData( double.NaN, double.NaN, 0.0)] - [InlineData( 0.0, 1.0, CrossPlatformMachineEpsilon * 10)] - [InlineData( 0.31830988618379067, 0.94976571538163866, CrossPlatformMachineEpsilon)] // value: (1 / pi) - [InlineData( 0.43429448190325183, 0.90716712923909839, CrossPlatformMachineEpsilon)] // value: (log10(e)) - [InlineData( 0.63661977236758134, 0.80410982822879171, CrossPlatformMachineEpsilon)] // value: (2 / pi) - [InlineData( 0.69314718055994531, 0.76923890136397213, CrossPlatformMachineEpsilon)] // value: (ln(2)) - [InlineData( 0.70710678118654752, 0.76024459707563015, CrossPlatformMachineEpsilon)] // value: (1 / sqrt(2)) - [InlineData( 0.78539816339744831, 0.70710678118654752, CrossPlatformMachineEpsilon)] // value: (pi / 4), expected: (1 / sqrt(2)) - [InlineData( 1.0, 0.54030230586813972, CrossPlatformMachineEpsilon)] - [InlineData( 1.1283791670955126, 0.42812514788535792, CrossPlatformMachineEpsilon)] // value: (2 / sqrt(pi)) - [InlineData( 1.4142135623730950, 0.15594369476537447, CrossPlatformMachineEpsilon)] // value: (sqrt(2)) - [InlineData( 1.4426950408889634, 0.12775121753523991, CrossPlatformMachineEpsilon)] // value: (log2(e)) - [InlineData( 1.5707963267948966, 0.0, CrossPlatformMachineEpsilon)] // value: (pi / 2) - [InlineData( 2.3025850929940457, -0.66820151019031295, CrossPlatformMachineEpsilon)] // value: (ln(10)) - [InlineData( 2.7182818284590452, -0.91173391478696510, CrossPlatformMachineEpsilon)] // value: (e) - [InlineData( 3.1415926535897932, -1.0, CrossPlatformMachineEpsilon * 10)] // value: (pi) - [InlineData( double.PositiveInfinity, double.NaN, 0.0)] + [MemberData(nameof(GenericMathTestMemberData.CosDouble), MemberType = typeof(GenericMathTestMemberData))] public static void Cos(double value, double expectedResult, double allowedVariance) { AssertExtensions.Equal(expectedResult, Math.Cos(value), allowedVariance); @@ -1354,80 +1322,14 @@ public static void Sign_Single() } [Theory] - [InlineData( double.NegativeInfinity, double.NaN, 0.0)] - [InlineData(-3.1415926535897932, -0.0, CrossPlatformMachineEpsilon)] // value: -(pi) - [InlineData(-2.7182818284590452, -0.41078129050290870, CrossPlatformMachineEpsilon)] // value: -(e) - [InlineData(-2.3025850929940457, -0.74398033695749319, CrossPlatformMachineEpsilon)] // value: -(ln(10)) - [InlineData(-1.5707963267948966, -1.0, CrossPlatformMachineEpsilon * 10)] // value: -(pi / 2) - [InlineData(-1.4426950408889634, -0.99180624439366372, CrossPlatformMachineEpsilon)] // value: -(log2(e)) - [InlineData(-1.4142135623730950, -0.98776594599273553, CrossPlatformMachineEpsilon)] // value: -(sqrt(2)) - [InlineData(-1.1283791670955126, -0.90371945743584630, CrossPlatformMachineEpsilon)] // value: -(2 / sqrt(pi)) - [InlineData(-1.0, -0.84147098480789651, CrossPlatformMachineEpsilon)] - [InlineData(-0.78539816339744831, -0.70710678118654752, CrossPlatformMachineEpsilon)] // value: -(pi / 4), expected: -(1 / sqrt(2)) - [InlineData(-0.70710678118654752, -0.64963693908006244, CrossPlatformMachineEpsilon)] // value: -(1 / sqrt(2)) - [InlineData(-0.69314718055994531, -0.63896127631363480, CrossPlatformMachineEpsilon)] // value: -(ln(2)) - [InlineData(-0.63661977236758134, -0.59448076852482208, CrossPlatformMachineEpsilon)] // value: -(2 / pi) - [InlineData(-0.43429448190325183, -0.42077048331375735, CrossPlatformMachineEpsilon)] // value: -(log10(e)) - [InlineData(-0.31830988618379067, -0.31296179620778659, CrossPlatformMachineEpsilon)] // value: -(1 / pi) - [InlineData(-0.0, -0.0, 0.0)] - [InlineData( double.NaN, double.NaN, 0.0)] - [InlineData( 0.0, 0.0, 0.0)] - [InlineData( 0.31830988618379067, 0.31296179620778659, CrossPlatformMachineEpsilon)] // value: (1 / pi) - [InlineData( 0.43429448190325183, 0.42077048331375735, CrossPlatformMachineEpsilon)] // value: (log10(e)) - [InlineData( 0.63661977236758134, 0.59448076852482208, CrossPlatformMachineEpsilon)] // value: (2 / pi) - [InlineData( 0.69314718055994531, 0.63896127631363480, CrossPlatformMachineEpsilon)] // value: (ln(2)) - [InlineData( 0.70710678118654752, 0.64963693908006244, CrossPlatformMachineEpsilon)] // value: (1 / sqrt(2)) - [InlineData( 0.78539816339744831, 0.70710678118654752, CrossPlatformMachineEpsilon)] // value: (pi / 4), expected: (1 / sqrt(2)) - [InlineData( 1.0, 0.84147098480789651, CrossPlatformMachineEpsilon)] - [InlineData( 1.1283791670955126, 0.90371945743584630, CrossPlatformMachineEpsilon)] // value: (2 / sqrt(pi)) - [InlineData( 1.4142135623730950, 0.98776594599273553, CrossPlatformMachineEpsilon)] // value: (sqrt(2)) - [InlineData( 1.4426950408889634, 0.99180624439366372, CrossPlatformMachineEpsilon)] // value: (log2(e)) - [InlineData( 1.5707963267948966, 1.0, CrossPlatformMachineEpsilon * 10)] // value: (pi / 2) - [InlineData( 2.3025850929940457, 0.74398033695749319, CrossPlatformMachineEpsilon)] // value: (ln(10)) - [InlineData( 2.7182818284590452, 0.41078129050290870, CrossPlatformMachineEpsilon)] // value: (e) - [InlineData( 3.1415926535897932, 0.0, CrossPlatformMachineEpsilon)] // value: (pi) - [InlineData( double.PositiveInfinity, double.NaN, 0.0)] + [MemberData(nameof(GenericMathTestMemberData.SinDouble), MemberType = typeof(GenericMathTestMemberData))] public static void Sin(double value, double expectedResult, double allowedVariance) { AssertExtensions.Equal(expectedResult, Math.Sin(value), allowedVariance); } [Theory] - [InlineData( double.NegativeInfinity, double.NaN, double.NaN, 0.0, 0.0)] - [InlineData(-1e18, 0.9929693207404051, 0.11837199021871073, 0.0002, 0.002)] // https://github.com/dotnet/runtime/issues/98204 - [InlineData(-3.1415926535897932, -0.0, -1.0, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon * 10)] // value: -(pi) - [InlineData(-2.7182818284590452, -0.41078129050290870, -0.91173391478696510, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(e) - [InlineData(-2.3025850929940457, -0.74398033695749319, -0.66820151019031295, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(ln(10)) - [InlineData(-1.5707963267948966, -1.0, 0.0, CrossPlatformMachineEpsilon * 10, CrossPlatformMachineEpsilon)] // value: -(pi / 2) - [InlineData(-1.4426950408889634, -0.99180624439366372, 0.12775121753523991, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(log2(e)) - [InlineData(-1.4142135623730950, -0.98776594599273553, 0.15594369476537447, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(sqrt(2)) - [InlineData(-1.1283791670955126, -0.90371945743584630, 0.42812514788535792, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(2 / sqrt(pi)) - [InlineData(-1.0, -0.84147098480789651, 0.54030230586813972, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] - [InlineData(-0.78539816339744831, -0.70710678118654752, 0.70710678118654752, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(pi / 4), expected_sin: -(1 / sqrt(2)), expected_cos: 1 - [InlineData(-0.70710678118654752, -0.64963693908006244, 0.76024459707563015, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(1 / sqrt(2)) - [InlineData(-0.69314718055994531, -0.63896127631363480, 0.76923890136397213, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(ln(2)) - [InlineData(-0.63661977236758134, -0.59448076852482208, 0.80410982822879171, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(2 / pi) - [InlineData(-0.43429448190325183, -0.42077048331375735, 0.90716712923909839, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(log10(e)) - [InlineData(-0.31830988618379067, -0.31296179620778659, 0.94976571538163866, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(1 / pi) - [InlineData(-0.0, -0.0, 1.0, 0.0, CrossPlatformMachineEpsilon * 10)] - [InlineData( double.NaN, double.NaN, double.NaN, 0.0, 0.0)] - [InlineData( 0.0, 0.0, 1.0, 0.0, CrossPlatformMachineEpsilon * 10)] - [InlineData( 0.31830988618379067, 0.31296179620778659, 0.94976571538163866, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (1 / pi) - [InlineData( 0.43429448190325183, 0.42077048331375735, 0.90716712923909839, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (log10(e)) - [InlineData( 0.63661977236758134, 0.59448076852482208, 0.80410982822879171, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (2 / pi) - [InlineData( 0.69314718055994531, 0.63896127631363480, 0.76923890136397213, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (ln(2)) - [InlineData( 0.70710678118654752, 0.64963693908006244, 0.76024459707563015, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (1 / sqrt(2)) - [InlineData( 0.78539816339744831, 0.70710678118654752, 0.70710678118654752, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (pi / 4), expected_sin: (1 / sqrt(2)), expected_cos: 1 - [InlineData( 1.0, 0.84147098480789651, 0.54030230586813972, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] - [InlineData( 1.1283791670955126, 0.90371945743584630, 0.42812514788535792, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (2 / sqrt(pi)) - [InlineData( 1.4142135623730950, 0.98776594599273553, 0.15594369476537447, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (sqrt(2)) - [InlineData( 1.4426950408889634, 0.99180624439366372, 0.12775121753523991, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (log2(e)) - [InlineData( 1.5707963267948966, 1.0, 0.0, CrossPlatformMachineEpsilon * 10, CrossPlatformMachineEpsilon)] // value: (pi / 2) - [InlineData( 2.3025850929940457, 0.74398033695749319, -0.66820151019031295, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (ln(10)) - [InlineData( 2.7182818284590452, 0.41078129050290870, -0.91173391478696510, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (e) - [InlineData( 3.1415926535897932, 0.0, -1.0, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon * 10)] // value: (pi) - [InlineData( 1e18, -0.9929693207404051, 0.11837199021871073, 0.0002, 0.002)] // https://github.com/dotnet/runtime/issues/98204 - [InlineData( double.PositiveInfinity, double.NaN, double.NaN, 0.0, 0.0)] + [MemberData(nameof(GenericMathTestMemberData.SinCosDouble), MemberType = typeof(GenericMathTestMemberData))] public static void SinCos(double value, double expectedResultSin, double expectedResultCos, double allowedVarianceSin, double allowedVarianceCos) { (double resultSin, double resultCos) = Math.SinCos(value); diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/MathF.cs b/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/MathF.cs index 565c00a986b29..1363a2b407b01 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/MathF.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/MathF.cs @@ -584,39 +584,7 @@ public static void CopySign(float x, float y, float expectedResult) } [Theory] - [InlineData(float.NegativeInfinity, float.NaN, 0.0f)] - [InlineData(-3.14159265f, -1.0f, CrossPlatformMachineEpsilon * 10)] // value: -(pi) - [InlineData(-2.71828183f, -0.911733918f, CrossPlatformMachineEpsilon)] // value: -(e) - [InlineData(-2.30258509f, -0.668201510f, CrossPlatformMachineEpsilon)] // value: -(ln(10)) - [InlineData(-1.57079633f, 0.0f, CrossPlatformMachineEpsilon)] // value: -(pi / 2) - [InlineData(-1.44269504f, 0.127751218f, CrossPlatformMachineEpsilon)] // value: -(log2(e)) - [InlineData(-1.41421356f, 0.155943695f, CrossPlatformMachineEpsilon)] // value: -(sqrt(2)) - [InlineData(-1.12837917f, 0.428125148f, CrossPlatformMachineEpsilon)] // value: -(2 / sqrt(pi)) - [InlineData(-1.0f, 0.540302306f, CrossPlatformMachineEpsilon)] - [InlineData(-0.785398163f, 0.707106781f, CrossPlatformMachineEpsilon)] // value: -(pi / 4), expected: (1 / sqrt(2)) - [InlineData(-0.707106781f, 0.760244597f, CrossPlatformMachineEpsilon)] // value: -(1 / sqrt(2)) - [InlineData(-0.693147181f, 0.769238901f, CrossPlatformMachineEpsilon)] // value: -(ln(2)) - [InlineData(-0.636619772f, 0.804109828f, CrossPlatformMachineEpsilon)] // value: -(2 / pi) - [InlineData(-0.434294482f, 0.907167129f, CrossPlatformMachineEpsilon)] // value: -(log10(e)) - [InlineData(-0.318309886f, 0.949765715f, CrossPlatformMachineEpsilon)] // value: -(1 / pi) - [InlineData(-0.0f, 1.0f, CrossPlatformMachineEpsilon * 10)] - [InlineData(float.NaN, float.NaN, 0.0f)] - [InlineData(0.0f, 1.0f, CrossPlatformMachineEpsilon * 10)] - [InlineData(0.318309886f, 0.949765715f, CrossPlatformMachineEpsilon)] // value: (1 / pi) - [InlineData(0.434294482f, 0.907167129f, CrossPlatformMachineEpsilon)] // value: (log10(e)) - [InlineData(0.636619772f, 0.804109828f, CrossPlatformMachineEpsilon)] // value: (2 / pi) - [InlineData(0.693147181f, 0.769238901f, CrossPlatformMachineEpsilon)] // value: (ln(2)) - [InlineData(0.707106781f, 0.760244597f, CrossPlatformMachineEpsilon)] // value: (1 / sqrt(2)) - [InlineData(0.785398163f, 0.707106781f, CrossPlatformMachineEpsilon)] // value: (pi / 4), expected: (1 / sqrt(2)) - [InlineData(1.0f, 0.540302306f, CrossPlatformMachineEpsilon)] - [InlineData(1.12837917f, 0.428125148f, CrossPlatformMachineEpsilon)] // value: (2 / sqrt(pi)) - [InlineData(1.41421356f, 0.155943695f, CrossPlatformMachineEpsilon)] // value: (sqrt(2)) - [InlineData(1.44269504f, 0.127751218f, CrossPlatformMachineEpsilon)] // value: (log2(e)) - [InlineData(1.57079633f, 0.0f, CrossPlatformMachineEpsilon)] // value: (pi / 2) - [InlineData(2.30258509f, -0.668201510f, CrossPlatformMachineEpsilon)] // value: (ln(10)) - [InlineData(2.71828183f, -0.911733918f, CrossPlatformMachineEpsilon)] // value: (e) - [InlineData(3.14159265f, -1.0f, CrossPlatformMachineEpsilon * 10)] // value: (pi) - [InlineData(float.PositiveInfinity, float.NaN, 0.0f)] + [MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))] public static void Cos(float value, float expectedResult, float allowedVariance) { AssertExtensions.Equal(expectedResult, MathF.Cos(value), allowedVariance); @@ -1349,80 +1317,14 @@ public static void Sign() } [Theory] - [InlineData(float.NegativeInfinity, float.NaN, 0.0f)] - [InlineData(-3.14159265f, -0.0f, CrossPlatformMachineEpsilon)] // value: -(pi) - [InlineData(-2.71828183f, -0.410781291f, CrossPlatformMachineEpsilon)] // value: -(e) - [InlineData(-2.30258509f, -0.743980337f, CrossPlatformMachineEpsilon)] // value: -(ln(10)) - [InlineData(-1.57079633f, -1.0f, CrossPlatformMachineEpsilon * 10)] // value: -(pi / 2) - [InlineData(-1.44269504f, -0.991806244f, CrossPlatformMachineEpsilon)] // value: -(log2(e)) - [InlineData(-1.41421356f, -0.987765946f, CrossPlatformMachineEpsilon)] // value: -(sqrt(2)) - [InlineData(-1.12837917f, -0.903719457f, CrossPlatformMachineEpsilon)] // value: -(2 / sqrt(pi)) - [InlineData(-1.0f, -0.841470985f, CrossPlatformMachineEpsilon)] - [InlineData(-0.785398163f, -0.707106781f, CrossPlatformMachineEpsilon)] // value: -(pi / 4), expected: -(1 / sqrt(2)) - [InlineData(-0.707106781f, -0.649636939f, CrossPlatformMachineEpsilon)] // value: -(1 / sqrt(2)) - [InlineData(-0.693147181f, -0.638961276f, CrossPlatformMachineEpsilon)] // value: -(ln(2)) - [InlineData(-0.636619772f, -0.594480769f, CrossPlatformMachineEpsilon)] // value: -(2 / pi) - [InlineData(-0.434294482f, -0.420770483f, CrossPlatformMachineEpsilon)] // value: -(log10(e)) - [InlineData(-0.318309886f, -0.312961796f, CrossPlatformMachineEpsilon)] // value: -(1 / pi) - [InlineData(-0.0f, -0.0f, 0.0f)] - [InlineData(float.NaN, float.NaN, 0.0f)] - [InlineData(0.0f, 0.0f, 0.0f)] - [InlineData(0.318309886f, 0.312961796f, CrossPlatformMachineEpsilon)] // value: (1 / pi) - [InlineData(0.434294482f, 0.420770483f, CrossPlatformMachineEpsilon)] // value: (log10(e)) - [InlineData(0.636619772f, 0.594480769f, CrossPlatformMachineEpsilon)] // value: (2 / pi) - [InlineData(0.693147181f, 0.638961276f, CrossPlatformMachineEpsilon)] // value: (ln(2)) - [InlineData(0.707106781f, 0.649636939f, CrossPlatformMachineEpsilon)] // value: (1 / sqrt(2)) - [InlineData(0.785398163f, 0.707106781f, CrossPlatformMachineEpsilon)] // value: (pi / 4), expected: (1 / sqrt(2)) - [InlineData(1.0f, 0.841470985f, CrossPlatformMachineEpsilon)] - [InlineData(1.12837917f, 0.903719457f, CrossPlatformMachineEpsilon)] // value: (2 / sqrt(pi)) - [InlineData(1.41421356f, 0.987765946f, CrossPlatformMachineEpsilon)] // value: (sqrt(2)) - [InlineData(1.44269504f, 0.991806244f, CrossPlatformMachineEpsilon)] // value: (log2(e)) - [InlineData(1.57079633f, 1.0f, CrossPlatformMachineEpsilon * 10)] // value: (pi / 2) - [InlineData(2.30258509f, 0.743980337f, CrossPlatformMachineEpsilon)] // value: (ln(10)) - [InlineData(2.71828183f, 0.410781291f, CrossPlatformMachineEpsilon)] // value: (e) - [InlineData(3.14159265f, 0.0f, CrossPlatformMachineEpsilon)] // value: (pi) - [InlineData(float.PositiveInfinity, float.NaN, 0.0f)] + [MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))] public static void Sin(float value, float expectedResult, float allowedVariance) { AssertExtensions.Equal(expectedResult, MathF.Sin(value), allowedVariance); } [Theory] - [InlineData( float.NegativeInfinity, float.NaN, float.NaN, 0.0f, 0.0f)] - [InlineData(-1e8f, -0.931639, -0.36338508, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // https://github.com/dotnet/runtime/issues/98204 - [InlineData(-3.14159265f, -0.0f, -1.0f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon * 10)] // value: -(pi) - [InlineData(-2.71828183f, -0.410781291f, -0.911733918f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(e) - [InlineData(-2.30258509f, -0.743980337f, -0.668201510f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(ln(10)) - [InlineData(-1.57079633f, -1.0f, 0.0f, CrossPlatformMachineEpsilon * 10, CrossPlatformMachineEpsilon)] // value: -(pi / 2) - [InlineData(-1.44269504f, -0.991806244f, 0.127751218f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(log2(e)) - [InlineData(-1.41421356f, -0.987765946f, 0.155943695f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(sqrt(2)) - [InlineData(-1.12837917f, -0.903719457f, 0.428125148f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(2 / sqrt(pi)) - [InlineData(-1.0f, -0.841470985f, 0.540302306f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] - [InlineData(-0.785398163f, -0.707106781f, 0.707106781f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(pi / 4), expected_sin: -(1 / sqrt(2)), expected_cos: 1 - [InlineData(-0.707106781f, -0.649636939f, 0.760244597f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(1 / sqrt(2)) - [InlineData(-0.693147181f, -0.638961276f, 0.769238901f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(ln(2)) - [InlineData(-0.636619772f, -0.594480769f, 0.804109828f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(2 / pi) - [InlineData(-0.434294482f, -0.420770483f, 0.907167129f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(log10(e)) - [InlineData(-0.318309886f, -0.312961796f, 0.949765715f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: -(1 / pi) - [InlineData(-0.0f, -0.0f, 1.0f, 0.0f, CrossPlatformMachineEpsilon * 10)] - [InlineData( float.NaN, float.NaN, float.NaN, 0.0f, 0.0f)] - [InlineData( 0.0f, 0.0f, 1.0f, 0.0f, CrossPlatformMachineEpsilon * 10)] - [InlineData( 0.318309886f, 0.312961796f, 0.949765715f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (1 / pi) - [InlineData( 0.434294482f, 0.420770483f, 0.907167129f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (log10(e)) - [InlineData( 0.636619772f, 0.594480769f, 0.804109828f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (2 / pi) - [InlineData( 0.693147181f, 0.638961276f, 0.769238901f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (ln(2)) - [InlineData( 0.707106781f, 0.649636939f, 0.760244597f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (1 / sqrt(2)) - [InlineData( 0.785398163f, 0.707106781f, 0.707106781f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (pi / 4), expected_sin: (1 / sqrt(2)), expected_cos: 1 - [InlineData( 1.0f, 0.841470985f, 0.540302306f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] - [InlineData( 1.12837917f, 0.903719457f, 0.428125148f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (2 / sqrt(pi)) - [InlineData( 1.41421356f, 0.987765946f, 0.155943695f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (sqrt(2)) - [InlineData( 1.44269504f, 0.991806244f, 0.127751218f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (log2(e)) - [InlineData( 1.57079633f, 1.0f, 0.0f, CrossPlatformMachineEpsilon * 10, CrossPlatformMachineEpsilon)] // value: (pi / 2) - [InlineData( 2.30258509f, 0.743980337f, -0.668201510f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (ln(10)) - [InlineData( 2.71828183f, 0.410781291f, -0.911733918f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // value: (e) - [InlineData( 3.14159265f, 0.0f, -1.0f, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon * 10)] // value: (pi) - [InlineData( 1e8f, 0.931639, -0.36338508, CrossPlatformMachineEpsilon, CrossPlatformMachineEpsilon)] // https://github.com/dotnet/runtime/issues/98204 - [InlineData( float.PositiveInfinity, float.NaN, float.NaN, 0.0f, 0.0f)] + [MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))] public static void SinCos(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos) { (float resultSin, float resultCos) = MathF.SinCos(value);