Use generic math in System.Numerics.Vectors (#60365) (#60905)
authorSychev Vadim <svddroid@gmail.com>
Fri, 11 Feb 2022 21:54:24 +0000 (00:54 +0300)
committerGitHub <noreply@github.com>
Fri, 11 Feb 2022 21:54:24 +0000 (13:54 -0800)
* Use generic math in System.Numerics.Vectors (#60365)

* Add more use of the Generic Math (#60365)

* Got rid of the dynamic cast (#60365)

Co-authored-by: Tanner Gooding <tagoo@outlook.com>
src/libraries/System.Numerics.Vectors/System.Numerics.Vectors.sln
src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs
src/libraries/System.Numerics.Vectors/tests/System.Numerics.Vectors.Tests.csproj
src/libraries/System.Numerics.Vectors/tests/Util.cs

index c829f21..e05d844 100644 (file)
@@ -26,18 +26,27 @@ EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{ED90FF1C-59D4-4AB0-860E-2872ECA1BFEC}"
 EndProject
 Global
+       GlobalSection(SharedMSBuildProjectFiles) = preSolution
+               ..\System.Private.CoreLib\src\System.Private.CoreLib.Shared.projitems*{634a3b2b-09f5-4810-b630-ade4d36c47df}*SharedItemsImports = 5
+       EndGlobalSection
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Checked|Any CPU = Checked|Any CPU
+               Checked|x64 = Checked|x64
+               Checked|x86 = Checked|x86
                Debug|Any CPU = Debug|Any CPU
                Debug|x64 = Debug|x64
                Debug|x86 = Debug|x86
                Release|Any CPU = Release|Any CPU
                Release|x64 = Release|x64
                Release|x86 = Release|x86
-               Checked|Any CPU = Checked|Any CPU
-               Checked|x64 = Checked|x64
-               Checked|x86 = Checked|x86
        EndGlobalSection
        GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|Any CPU.ActiveCfg = Checked|x64
+               {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|Any CPU.Build.0 = Checked|x64
+               {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x64.ActiveCfg = Checked|x64
+               {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x64.Build.0 = Checked|x64
+               {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x86.ActiveCfg = Checked|x86
+               {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x86.Build.0 = Checked|x86
                {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Debug|Any CPU.ActiveCfg = Debug|x64
                {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Debug|Any CPU.Build.0 = Debug|x64
                {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Debug|x64.ActiveCfg = Debug|x64
@@ -50,12 +59,12 @@ Global
                {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Release|x64.Build.0 = Release|x64
                {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Release|x86.ActiveCfg = Release|x86
                {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Release|x86.Build.0 = Release|x86
-               {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|Any CPU.ActiveCfg = Checked|x64
-               {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|Any CPU.Build.0 = Checked|x64
-               {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x64.ActiveCfg = Checked|x64
-               {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x64.Build.0 = Checked|x64
-               {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x86.ActiveCfg = Checked|x86
-               {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x86.Build.0 = Checked|x86
+               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
+               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|Any CPU.Build.0 = Debug|Any CPU
+               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x64.ActiveCfg = Debug|Any CPU
+               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x64.Build.0 = Debug|Any CPU
+               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x86.ActiveCfg = Debug|Any CPU
+               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x86.Build.0 = Debug|Any CPU
                {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -68,12 +77,12 @@ Global
                {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Release|x64.Build.0 = Release|Any CPU
                {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Release|x86.ActiveCfg = Release|Any CPU
                {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Release|x86.Build.0 = Release|Any CPU
-               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
-               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|Any CPU.Build.0 = Debug|Any CPU
-               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x64.ActiveCfg = Debug|Any CPU
-               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x64.Build.0 = Debug|Any CPU
-               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x86.ActiveCfg = Debug|Any CPU
-               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x86.Build.0 = Debug|Any CPU
+               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
+               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|Any CPU.Build.0 = Debug|Any CPU
+               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x64.ActiveCfg = Debug|Any CPU
+               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x64.Build.0 = Debug|Any CPU
+               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x86.ActiveCfg = Debug|Any CPU
+               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x86.Build.0 = Debug|Any CPU
                {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -86,12 +95,12 @@ Global
                {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Release|x64.Build.0 = Release|Any CPU
                {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Release|x86.ActiveCfg = Release|Any CPU
                {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Release|x86.Build.0 = Release|Any CPU
-               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
-               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|Any CPU.Build.0 = Debug|Any CPU
-               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x64.ActiveCfg = Debug|Any CPU
-               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x64.Build.0 = Debug|Any CPU
-               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x86.ActiveCfg = Debug|Any CPU
-               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x86.Build.0 = Debug|Any CPU
+               {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
+               {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|Any CPU.Build.0 = Debug|Any CPU
+               {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x64.ActiveCfg = Debug|Any CPU
+               {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x64.Build.0 = Debug|Any CPU
+               {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x86.ActiveCfg = Debug|Any CPU
+               {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x86.Build.0 = Debug|Any CPU
                {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -104,12 +113,12 @@ Global
                {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Release|x64.Build.0 = Release|Any CPU
                {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Release|x86.ActiveCfg = Release|Any CPU
                {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Release|x86.Build.0 = Release|Any CPU
-               {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
-               {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|Any CPU.Build.0 = Debug|Any CPU
-               {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x64.ActiveCfg = Debug|Any CPU
-               {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x64.Build.0 = Debug|Any CPU
-               {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x86.ActiveCfg = Debug|Any CPU
-               {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x86.Build.0 = Debug|Any CPU
+               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
+               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|Any CPU.Build.0 = Debug|Any CPU
+               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x64.ActiveCfg = Debug|Any CPU
+               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x64.Build.0 = Debug|Any CPU
+               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x86.ActiveCfg = Debug|Any CPU
+               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x86.Build.0 = Debug|Any CPU
                {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -122,12 +131,12 @@ Global
                {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Release|x64.Build.0 = Release|Any CPU
                {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Release|x86.ActiveCfg = Release|Any CPU
                {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Release|x86.Build.0 = Release|Any CPU
-               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
-               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|Any CPU.Build.0 = Debug|Any CPU
-               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x64.ActiveCfg = Debug|Any CPU
-               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x64.Build.0 = Debug|Any CPU
-               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x86.ActiveCfg = Debug|Any CPU
-               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x86.Build.0 = Debug|Any CPU
+               {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
+               {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|Any CPU.Build.0 = Debug|Any CPU
+               {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x64.ActiveCfg = Debug|Any CPU
+               {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x64.Build.0 = Debug|Any CPU
+               {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x86.ActiveCfg = Debug|Any CPU
+               {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x86.Build.0 = Debug|Any CPU
                {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -140,12 +149,12 @@ Global
                {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Release|x64.Build.0 = Release|Any CPU
                {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Release|x86.ActiveCfg = Release|Any CPU
                {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Release|x86.Build.0 = Release|Any CPU
-               {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
-               {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|Any CPU.Build.0 = Debug|Any CPU
-               {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x64.ActiveCfg = Debug|Any CPU
-               {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x64.Build.0 = Debug|Any CPU
-               {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x86.ActiveCfg = Debug|Any CPU
-               {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x86.Build.0 = Debug|Any CPU
+               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
+               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|Any CPU.Build.0 = Debug|Any CPU
+               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x64.ActiveCfg = Debug|Any CPU
+               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x64.Build.0 = Debug|Any CPU
+               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x86.ActiveCfg = Debug|Any CPU
+               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x86.Build.0 = Debug|Any CPU
                {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -158,12 +167,12 @@ Global
                {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Release|x64.Build.0 = Release|Any CPU
                {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Release|x86.ActiveCfg = Release|Any CPU
                {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Release|x86.Build.0 = Release|Any CPU
-               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
-               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|Any CPU.Build.0 = Debug|Any CPU
-               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x64.ActiveCfg = Debug|Any CPU
-               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x64.Build.0 = Debug|Any CPU
-               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x86.ActiveCfg = Debug|Any CPU
-               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x86.Build.0 = Debug|Any CPU
+               {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
+               {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|Any CPU.Build.0 = Debug|Any CPU
+               {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x64.ActiveCfg = Debug|Any CPU
+               {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x64.Build.0 = Debug|Any CPU
+               {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x86.ActiveCfg = Debug|Any CPU
+               {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x86.Build.0 = Debug|Any CPU
                {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -176,12 +185,12 @@ Global
                {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Release|x64.Build.0 = Release|Any CPU
                {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Release|x86.ActiveCfg = Release|Any CPU
                {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Release|x86.Build.0 = Release|Any CPU
-               {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
-               {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|Any CPU.Build.0 = Debug|Any CPU
-               {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x64.ActiveCfg = Debug|Any CPU
-               {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x64.Build.0 = Debug|Any CPU
-               {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x86.ActiveCfg = Debug|Any CPU
-               {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x86.Build.0 = Debug|Any CPU
+               {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
+               {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|Any CPU.Build.0 = Debug|Any CPU
+               {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x64.ActiveCfg = Debug|Any CPU
+               {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x64.Build.0 = Debug|Any CPU
+               {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x86.ActiveCfg = Debug|Any CPU
+               {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x86.Build.0 = Debug|Any CPU
                {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -194,12 +203,12 @@ Global
                {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Release|x64.Build.0 = Release|Any CPU
                {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Release|x86.ActiveCfg = Release|Any CPU
                {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Release|x86.Build.0 = Release|Any CPU
-               {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
-               {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|Any CPU.Build.0 = Debug|Any CPU
-               {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x64.ActiveCfg = Debug|Any CPU
-               {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x64.Build.0 = Debug|Any CPU
-               {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x86.ActiveCfg = Debug|Any CPU
-               {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x86.Build.0 = Debug|Any CPU
+               {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
+               {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|Any CPU.Build.0 = Debug|Any CPU
+               {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x64.ActiveCfg = Debug|Any CPU
+               {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x64.Build.0 = Debug|Any CPU
+               {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x86.ActiveCfg = Debug|Any CPU
+               {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x86.Build.0 = Debug|Any CPU
                {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -212,27 +221,21 @@ Global
                {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Release|x64.Build.0 = Release|Any CPU
                {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Release|x86.ActiveCfg = Release|Any CPU
                {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Release|x86.Build.0 = Release|Any CPU
-               {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
-               {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|Any CPU.Build.0 = Debug|Any CPU
-               {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x64.ActiveCfg = Debug|Any CPU
-               {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x64.Build.0 = Debug|Any CPU
-               {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x86.ActiveCfg = Debug|Any CPU
-               {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x86.Build.0 = Debug|Any CPU
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
        EndGlobalSection
        GlobalSection(NestedProjects) = preSolution
                {634A3B2B-09F5-4810-B630-ADE4D36C47DF} = {FC10C682-DF71-4EEA-A3A5-E716C1C88AC0}
+               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F} = {2C4425BA-8478-4BCB-B616-E6FC28ADEAB9}
+               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7} = {ED90FF1C-59D4-4AB0-860E-2872ECA1BFEC}
                {ED450846-85A0-4CED-B4D9-9EB769CF794B} = {FC10C682-DF71-4EEA-A3A5-E716C1C88AC0}
+               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B} = {2C4425BA-8478-4BCB-B616-E6FC28ADEAB9}
                {88F4A78E-4EF9-4EB6-995E-CD24152C4704} = {FC10C682-DF71-4EEA-A3A5-E716C1C88AC0}
+               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237} = {ED90FF1C-59D4-4AB0-860E-2872ECA1BFEC}
                {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598} = {FC10C682-DF71-4EEA-A3A5-E716C1C88AC0}
                {C6EDFA8A-956E-4398-B31F-FA87312BDF9B} = {FC10C682-DF71-4EEA-A3A5-E716C1C88AC0}
                {F99EAF58-533E-4941-A0C5-5101309D8AB9} = {FC10C682-DF71-4EEA-A3A5-E716C1C88AC0}
-               {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F} = {2C4425BA-8478-4BCB-B616-E6FC28ADEAB9}
-               {B38797B1-BB45-4B30-9D4F-79D9F4B3735B} = {2C4425BA-8478-4BCB-B616-E6FC28ADEAB9}
-               {5B2027FA-F43A-4E80-880F-B3A7A2720AA7} = {ED90FF1C-59D4-4AB0-860E-2872ECA1BFEC}
-               {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237} = {ED90FF1C-59D4-4AB0-860E-2872ECA1BFEC}
        EndGlobalSection
        GlobalSection(ExtensibilityGlobals) = postSolution
                SolutionGuid = {F9EDC1DC-52BE-4C40-90D2-41EE6FB7FA5C}
index 556e667..b7fbaec 100644 (file)
@@ -6,6 +6,7 @@ using System.Globalization;
 using System.Linq;
 using System.Reflection;
 using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
 using Xunit;
 using Xunit.Sdk;
 
@@ -14,6 +15,7 @@ namespace System.Numerics.Tests
     /// <summary>
     ///  Vector{T} tests that use random number generation and a unified generic test structure
     /// </summary>
+    [RequiresPreviewFeatures]
     public class GenericVectorTests
     {
         // Static constructor in top-level class\
@@ -515,7 +517,7 @@ namespace System.Numerics.Tests
         public void StaticOneVectorSingle() { TestStaticOneVector<float>(); }
         [Fact]
         public void StaticOneVectorDouble() { TestStaticOneVector<double>(); }
-        private void TestStaticOneVector<T>() where T : struct
+        private void TestStaticOneVector<T>() where T : struct, INumber<T>
         {
             Vector<T> vector = Vector<T>.One;
             T oneValue = Util.One<T>();
@@ -546,7 +548,7 @@ namespace System.Numerics.Tests
         public void StaticZeroVectorSingle() { TestStaticZeroVector<float>(); }
         [Fact]
         public void StaticZeroVectorDouble() { TestStaticZeroVector<double>(); }
-        private void TestStaticZeroVector<T>() where T : struct
+        private void TestStaticZeroVector<T>() where T : struct, INumber<T>
         {
             Vector<T> vector = Vector<T>.Zero;
             T zeroValue = Util.Zero<T>();
@@ -812,7 +814,7 @@ namespace System.Numerics.Tests
         public void EqualsVectorSingle() { TestEqualsVector<float>(); }
         [Fact]
         public void EqualsVectorDouble() { TestEqualsVector<double>(); }
-        private void TestEqualsVector<T>() where T : struct
+        private void TestEqualsVector<T>() where T : struct, INumber<T>
         {
             T[] values = GenerateRandomValuesForVector<T>();
             Vector<T> vector1 = new Vector<T>(values);
@@ -963,7 +965,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void AdditionDouble() { TestAddition<double>(); }
-        private void TestAddition<T>() where T : struct
+        private void TestAddition<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -993,7 +995,7 @@ namespace System.Numerics.Tests
         public void AdditionOverflowUInt64() { TestAdditionOverflow<ulong>(); }
         [Fact]
         public void AdditionOverflowInt64() { TestAdditionOverflow<long>(); }
-        private void TestAdditionOverflow<T>() where T : struct
+        private void TestAdditionOverflow<T>() where T : struct, INumber<T>
         {
             T maxValue = GetMaxValueExact<T>();
             Vector<T> maxValueVector = new Vector<T>(maxValue);
@@ -1030,7 +1032,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void SubtractionDouble() { TestSubtraction<double>(); }
-        private void TestSubtraction<T>() where T : struct
+        private void TestSubtraction<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -1060,7 +1062,7 @@ namespace System.Numerics.Tests
         public void SubtractionOverflowUInt64() { TestSubtractionOverflow<ulong>(); }
         [Fact]
         public void SubtractionOverflowInt64() { TestSubtractionOverflow<long>(); }
-        private void TestSubtractionOverflow<T>() where T : struct
+        private void TestSubtractionOverflow<T>() where T : struct, INumber<T>
         {
             T minValue = GetMinValueExact<T>();
             Vector<T> minValueVector = new Vector<T>(minValue);
@@ -1097,7 +1099,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void MultiplicationDouble() { TestMultiplication<double>(); }
-        private void TestMultiplication<T>() where T : struct
+        private void TestMultiplication<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -1133,7 +1135,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void MultiplicationWithScalarDouble() { TestMultiplicationWithScalar<double>(); }
-        private void TestMultiplicationWithScalar<T>() where T : struct
+        private void TestMultiplicationWithScalar<T>() where T : struct, INumber<T>
         {
             T[] values = GenerateRandomValuesForVector<T>();
             T factor = Util.GenerateSingleValue<T>(GetMinValue<T>(), GetMaxValue<T>());
@@ -1177,7 +1179,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void DivisionDouble() { TestDivision<double>(); }
-        private void TestDivision<T>() where T : struct
+        private void TestDivision<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             values1 = values1.Select(val => val.Equals(Util.Zero<T>()) ? Util.One<T>() : val).ToArray(); // Avoid divide-by-zero
@@ -1239,7 +1241,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void UnaryMinusDouble() { TestUnaryMinus<double>(); }
-        private void TestUnaryMinus<T>() where T : struct
+        private void TestUnaryMinus<T>() where T : struct, INumber<T>
         {
             T[] values = GenerateRandomValuesForVector<T>();
             Vector<T> vector = new Vector<T>(values);
@@ -1336,7 +1338,7 @@ namespace System.Numerics.Tests
         public void BitwiseXorOperatorUInt64() { TestBitwiseXorOperator<ulong>(); }
         [Fact]
         public void BitwiseXorOperatorInt64() { TestBitwiseXorOperator<long>(); }
-        private void TestBitwiseXorOperator<T>() where T : struct
+        private void TestBitwiseXorOperator<T>() where T : struct, IBitwiseOperators<T,T,T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -1368,7 +1370,7 @@ namespace System.Numerics.Tests
         public void BitwiseOnesComplementOperatorUInt64() { TestBitwiseOnesComplementOperator<ulong>(); }
         [Fact]
         public void BitwiseOnesComplementOperatorInt64() { TestBitwiseOnesComplementOperator<long>(); }
-        private void TestBitwiseOnesComplementOperator<T>() where T : struct
+        private void TestBitwiseOnesComplementOperator<T>() where T : struct, IBitwiseOperators<T,T,T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             Vector<T> randomVector1 = new Vector<T>(values1);
@@ -1398,7 +1400,7 @@ namespace System.Numerics.Tests
         public void BitwiseAndNotUInt64() { TestBitwiseAndNot<ulong>(); }
         [Fact]
         public void BitwiseAndNotInt64() { TestBitwiseAndNot<long>(); }
-        private void TestBitwiseAndNot<T>() where T : struct
+        private void TestBitwiseAndNot<T>() where T : struct, IBitwiseOperators<T,T,T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -1441,7 +1443,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void VectorGreaterThanDouble() { TestVectorGreaterThan<double>(); }
-        private void TestVectorGreaterThan<T>() where T : struct
+        private void TestVectorGreaterThan<T>() where T : struct, INumber<T>
         {
             var values1 = GenerateRandomValuesForVector<T>();
             var values2 = GenerateRandomValuesForVector<T>();
@@ -1480,7 +1482,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void GreaterThanOrEqualDouble() { TestVectorGreaterThanOrEqual<double>(); }
-        private void TestVectorGreaterThanOrEqual<T>() where T : struct
+        private void TestVectorGreaterThanOrEqual<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -1735,7 +1737,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void LessThanDouble() { TestVectorLessThan<double>(); }
-        private void TestVectorLessThan<T>() where T : struct
+        private void TestVectorLessThan<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -1774,7 +1776,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void LessThanOrEqualDouble() { TestVectorLessThanOrEqual<double>(); }
-        private void TestVectorLessThanOrEqual<T>() where T : struct
+        private void TestVectorLessThanOrEqual<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -1813,7 +1815,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void LessThanAnyDouble() { TestVectorLessThanAny<double>(); }
-        private void TestVectorLessThanAny<T>() where T : struct
+        private void TestVectorLessThanAny<T>() where T : struct, INumber<T>
         {
             T[] values1 = new T[Vector<T>.Count];
             for (int g = 0; g < Vector<T>.Count; g++)
@@ -1848,7 +1850,7 @@ namespace System.Numerics.Tests
         public void LessThanAllSingle() { TestVectorLessThanAll<float>(); }
         [Fact]
         public void LessThanAllDouble() { TestVectorLessThanAll<double>(); }
-        private void TestVectorLessThanAll<T>() where T : struct
+        private void TestVectorLessThanAll<T>() where T : struct, INumber<T>
         {
             T[] values1 = new T[Vector<T>.Count];
             for (int g = 0; g < Vector<T>.Count; g++)
@@ -2003,7 +2005,7 @@ namespace System.Numerics.Tests
         public void VectorEqualsSingle() { TestVectorEquals<float>(); }
         [Fact]
         public void VectorEqualsDouble() { TestVectorEquals<double>(); }
-        private void TestVectorEquals<T>() where T : struct
+        private void TestVectorEquals<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2;
@@ -2048,7 +2050,7 @@ namespace System.Numerics.Tests
         public void VectorEqualsAnySingle() { TestVectorEqualsAny<float>(); }
         [Fact]
         public void VectorEqualsAnyDouble() { TestVectorEqualsAny<double>(); }
-        private void TestVectorEqualsAny<T>() where T : struct
+        private void TestVectorEqualsAny<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2;
@@ -2096,7 +2098,7 @@ namespace System.Numerics.Tests
         public void VectorEqualsAllSingle() { TestVectorEqualsAll<float>(); }
         [Fact]
         public void VectorEqualsAllDouble() { TestVectorEqualsAll<double>(); }
-        private void TestVectorEqualsAll<T>() where T : struct
+        private void TestVectorEqualsAll<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2;
@@ -2141,7 +2143,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void ConditionalSelectDouble() { TestConditionalSelect<double>(); }
-        private void TestConditionalSelect<T>() where T : struct
+        private void TestConditionalSelect<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -2195,7 +2197,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void DotProductDouble() { TestDotProduct<double>(); }
-        private void TestDotProduct<T>() where T : struct
+        private void TestDotProduct<T>() where T : struct, INumber<T>
         {
             T[] values1 = Util.GenerateRandomValues<T>(Vector<T>.Count);
             T[] values2 = Util.GenerateRandomValues<T>(Vector<T>.Count);
@@ -2233,7 +2235,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void MaxDouble() { TestMax<double>(); }
-        private void TestMax<T>() where T : struct
+        private void TestMax<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -2271,7 +2273,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void MinDouble() { TestMin<double>(); }
-        private void TestMin<T>() where T : struct
+        private void TestMin<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -2309,7 +2311,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void SquareRootDouble() { TestSquareRoot<double>(15); }
-        private void TestSquareRoot<T>(int precision = -1) where T : struct, IEquatable<T>
+        private void TestSquareRoot<T>(int precision = -1) where T : struct, INumber<T>, IEquatable<T>
         {
             T[] values = GenerateRandomValuesForVector<T>();
             Vector<T> vector = new Vector<T>(values);
@@ -2405,7 +2407,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void AbsDouble() { TestAbs<double>(); }
-        private void TestAbs<T>() where T : struct
+        private void TestAbs<T>() where T : struct, INumber<T>
         {
             T[] values = Util.GenerateRandomValues<T>(Vector<T>.Count, GetMinValue<T>() + 1, GetMaxValue<T>());
             Vector<T> vector = new Vector<T>(values);
@@ -2445,7 +2447,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void MultiplicationReflectionDouble() { TestMultiplicationReflection<double>(); }
-        private void TestMultiplicationReflection<T>() where T : struct
+        private void TestMultiplicationReflection<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -2484,7 +2486,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void AdditionReflectionDouble() { TestAdditionReflection<double>(); }
-        private void TestAdditionReflection<T>() where T : struct
+        private void TestAdditionReflection<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             T[] values2 = GenerateRandomValuesForVector<T>();
@@ -2523,7 +2525,7 @@ namespace System.Numerics.Tests
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))]
         public void DivisionReflectionDouble() { TestDivisionReflection<double>(); }
-        private void TestDivisionReflection<T>() where T : struct
+        private void TestDivisionReflection<T>() where T : struct, INumber<T>
         {
             T[] values1 = GenerateRandomValuesForVector<T>();
             values1 = values1.Select(val => val.Equals(Util.Zero<T>()) ? Util.One<T>() : val).ToArray(); // Avoid divide-by-zero
index c8cff88..ff4201d 100644 (file)
@@ -17,4 +17,8 @@
     <Compile Include="PlaneTests.cs" />
     <Compile Include="QuaternionTests.cs" />
   </ItemGroup>
+  <ItemGroup>
+    <!-- it's a reference assembly, but the project system doesn't know that - include it during compilation, but don't publish it -->
+    <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.Experimental\ref\System.Runtime.Experimental.csproj" IncludeAssets="compile" Private="false" />
+  </ItemGroup>
 </Project>
index 135b3fc..74affb1 100644 (file)
@@ -1,6 +1,8 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
+using System.Runtime.Versioning;
+
 namespace System.Numerics.Tests
 {
     public static class Util
@@ -89,150 +91,65 @@ namespace System.Numerics.Tests
             return value;
         }
 
-        public static T Abs<T>(T value) where T : struct
+        [RequiresPreviewFeatures]
+        public static T Abs<T>(T value) where T : INumber<T>
         {
-            // unsigned types
-            if      (value is byte)   return value;
-            else if (value is ushort) return value;
-            else if (value is uint)   return value;
-            else if (value is ulong)  return value;
-            // signed types
-            else if (value is short)  return (T)(ValueType)(short)  ( Math.Abs((short) (ValueType)value) );
-            else if (value is int)    return (T)(ValueType)(int)    ( Math.Abs((int)   (ValueType)value) );
-            else if (value is long)   return (T)(ValueType)(long)   ( Math.Abs((long)  (ValueType)value) );
-            else if (value is sbyte)  return (T)(ValueType)(sbyte)  ( Math.Abs((sbyte) (ValueType)value) );
-            else if (value is float)  return (T)(ValueType)(float)  ( Math.Abs((float) (ValueType)value) );
-            else if (value is double) return (T)(ValueType)(double) ( Math.Abs((double)(ValueType)value) );
-            else throw new NotImplementedException();
+            return T.Abs(value);
         }
-
-        public static T Sqrt<T>(T value) where T : struct
+        [RequiresPreviewFeatures]
+        public static T Sqrt<T>(T value) where T : struct, INumber<T>
         {
-            unchecked
-            {
-                if      (value is short)  return (T)(ValueType)(short)  ( Math.Sqrt((short) (ValueType)value) );
-                else if (value is int)    return (T)(ValueType)(int)    ( Math.Sqrt((int)   (ValueType)value) );
-                else if (value is long)   return (T)(ValueType)(long)   ( Math.Sqrt((long)  (ValueType)value) );
-                else if (value is ushort) return (T)(ValueType)(ushort) ( Math.Sqrt((ushort)(ValueType)value) );
-                else if (value is uint)   return (T)(ValueType)(uint)   ( Math.Sqrt((uint)  (ValueType)value) );
-                else if (value is ulong)  return (T)(ValueType)(ulong)  ( Math.Sqrt((ulong) (ValueType)value) );
-                else if (value is byte)   return (T)(ValueType)(byte)   ( Math.Sqrt((byte)  (ValueType)value) );
-                else if (value is sbyte)  return (T)(ValueType)(sbyte)  ( Math.Sqrt((sbyte) (ValueType)value) );
-                else if (value is float)  return (T)(ValueType)(float)  ( Math.Sqrt((float) (ValueType)value) );
-                else if (value is double) return (T)(ValueType)(double) ( Math.Sqrt((double)(ValueType)value) );
-                else throw new NotImplementedException();
-            }
+            double dValue = Create<T, double>(value);
+            double dSqrt = Math.Sqrt(dValue);
+            return T.CreateTruncating<double>(dSqrt);
         }
 
-        public static T Multiply<T>(T left, T right) where T : struct
+        [RequiresPreviewFeatures]
+        private static TSelf Create<TOther, TSelf>(TOther value)
+            where TOther : INumber<TOther>
+            where TSelf : INumber<TSelf>
+            => TSelf.Create<TOther>(value);
+
+        [RequiresPreviewFeatures]
+        public static T Multiply<T>(T left, T right) where T : INumber<T>
         {
-            unchecked
-            {
-                if      (left is short)  return (T)(ValueType)(short)  ( (short) (ValueType)left * (short) (ValueType)right );
-                else if (left is int)    return (T)(ValueType)(int)    ( (int)   (ValueType)left * (int)   (ValueType)right );
-                else if (left is long)   return (T)(ValueType)(long)   ( (long)  (ValueType)left * (long)  (ValueType)right );
-                else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left * (ushort)(ValueType)right );
-                else if (left is uint)   return (T)(ValueType)(uint)   ( (uint)  (ValueType)left * (uint)  (ValueType)right );
-                else if (left is ulong)  return (T)(ValueType)(ulong)  ( (ulong) (ValueType)left * (ulong) (ValueType)right );
-                else if (left is byte)   return (T)(ValueType)(byte)   ( (byte)  (ValueType)left * (byte)  (ValueType)right );
-                else if (left is sbyte)  return (T)(ValueType)(sbyte)  ( (sbyte) (ValueType)left * (sbyte) (ValueType)right );
-                else if (left is float)  return (T)(ValueType)(float)  ( (float) (ValueType)left * (float) (ValueType)right );
-                else if (left is double) return (T)(ValueType)(double) ( (double)(ValueType)left * (double)(ValueType)right );
-                else throw new NotImplementedException();
-            }
+            return left * right;
         }
 
-        public static T Divide<T>(T left, T right) where T : struct
+        [RequiresPreviewFeatures]
+        public static T Divide<T>(T left, T right) where T : INumber<T>
         {
-            if      (left is short)  return (T)(ValueType)(short)  ( (short) (ValueType)left / (short) (ValueType)right );
-            else if (left is int)    return (T)(ValueType)(int)    ( (int)   (ValueType)left / (int)   (ValueType)right );
-            else if (left is long)   return (T)(ValueType)(long)   ( (long)  (ValueType)left / (long)  (ValueType)right );
-            else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left / (ushort)(ValueType)right );
-            else if (left is uint)   return (T)(ValueType)(uint)   ( (uint)  (ValueType)left / (uint)  (ValueType)right );
-            else if (left is ulong)  return (T)(ValueType)(ulong)  ( (ulong) (ValueType)left / (ulong) (ValueType)right );
-            else if (left is byte)   return (T)(ValueType)(byte)   ( (byte)  (ValueType)left / (byte)  (ValueType)right );
-            else if (left is sbyte)  return (T)(ValueType)(sbyte)  ( (sbyte) (ValueType)left / (sbyte) (ValueType)right );
-            else if (left is float)  return (T)(ValueType)(float)  ( (float) (ValueType)left / (float) (ValueType)right );
-            else if (left is double) return (T)(ValueType)(double) ( (double)(ValueType)left / (double)(ValueType)right );
-            else throw new NotImplementedException();
+            return left / right;
         }
 
-        public static T Add<T>(T left, T right) where T : struct
+        [RequiresPreviewFeatures]
+        public static T Add<T>(T left, T right) where T : INumber<T>
         {
-            unchecked
-            {
-                if      (left is short)  return (T)(ValueType)(short)  ( (short) (ValueType)left + (short) (ValueType)right );
-                else if (left is int)    return (T)(ValueType)(int)    ( (int)   (ValueType)left + (int)   (ValueType)right );
-                else if (left is long)   return (T)(ValueType)(long)   ( (long)  (ValueType)left + (long)  (ValueType)right );
-                else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left + (ushort)(ValueType)right );
-                else if (left is uint)   return (T)(ValueType)(uint)   ( (uint)  (ValueType)left + (uint)  (ValueType)right );
-                else if (left is ulong)  return (T)(ValueType)(ulong)  ( (ulong) (ValueType)left + (ulong) (ValueType)right );
-                else if (left is byte)   return (T)(ValueType)(byte)   ( (byte)  (ValueType)left + (byte)  (ValueType)right );
-                else if (left is sbyte)  return (T)(ValueType)(sbyte)  ( (sbyte) (ValueType)left + (sbyte) (ValueType)right );
-                else if (left is float)  return (T)(ValueType)(float)  ( (float) (ValueType)left + (float) (ValueType)right );
-                else if (left is double) return (T)(ValueType)(double) ( (double)(ValueType)left + (double)(ValueType)right );
-                else throw new NotImplementedException();
-            }
+            return left + right;
         }
 
-        public static T Subtract<T>(T left, T right) where T : struct
+        [RequiresPreviewFeatures]
+        public static T Subtract<T>(T left, T right) where T : INumber<T>
         {
-            unchecked
-            {
-                if      (left is short)  return (T)(ValueType)(short)  ( (short) (ValueType)left - (short) (ValueType)right );
-                else if (left is int)    return (T)(ValueType)(int)    ( (int)   (ValueType)left - (int)   (ValueType)right );
-                else if (left is long)   return (T)(ValueType)(long)   ( (long)  (ValueType)left - (long)  (ValueType)right );
-                else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left - (ushort)(ValueType)right );
-                else if (left is uint)   return (T)(ValueType)(uint)   ( (uint)  (ValueType)left - (uint)  (ValueType)right );
-                else if (left is ulong)  return (T)(ValueType)(ulong)  ( (ulong) (ValueType)left - (ulong) (ValueType)right );
-                else if (left is byte)   return (T)(ValueType)(byte)   ( (byte)  (ValueType)left - (byte)  (ValueType)right );
-                else if (left is sbyte)  return (T)(ValueType)(sbyte)  ( (sbyte) (ValueType)left - (sbyte) (ValueType)right );
-                else if (left is float)  return (T)(ValueType)(float)  ( (float) (ValueType)left - (float) (ValueType)right );
-                else if (left is double) return (T)(ValueType)(double) ( (double)(ValueType)left - (double)(ValueType)right );
-                else throw new NotImplementedException();
-            }
+            return left - right;
         }
 
-        public static T Xor<T>(T left, T right) where T : struct
+        [RequiresPreviewFeatures]
+        public static T Xor<T>(T left, T right) where T : IBitwiseOperators<T, T, T>
         {
-            if      (left is short)  return (T)(ValueType)(short)  ( (short) (ValueType)left ^ (short) (ValueType)right );
-            else if (left is int)    return (T)(ValueType)(int)    ( (int)   (ValueType)left ^ (int)   (ValueType)right );
-            else if (left is long)   return (T)(ValueType)(long)   ( (long)  (ValueType)left ^ (long)  (ValueType)right );
-            else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left ^ (ushort)(ValueType)right );
-            else if (left is uint)   return (T)(ValueType)(uint)   ( (uint)  (ValueType)left ^ (uint)  (ValueType)right );
-            else if (left is ulong)  return (T)(ValueType)(ulong)  ( (ulong) (ValueType)left ^ (ulong) (ValueType)right );
-            else if (left is byte)   return (T)(ValueType)(byte)   ( (byte)  (ValueType)left ^ (byte)  (ValueType)right );
-            else if (left is sbyte)  return (T)(ValueType)(sbyte)  ( (sbyte) (ValueType)left ^ (sbyte) (ValueType)right );
-            else throw new NotImplementedException();
+            return left ^ right;
         }
 
-        public static T AndNot<T>(T left, T right) where T : struct
+        [RequiresPreviewFeatures]
+        public static T AndNot<T>(T left, T right) where T : IBitwiseOperators<T, T, T>
         {
-            if      (left is short)  return (T)(ValueType)(short)  ( (short) (ValueType)left & ~(short) (ValueType)right );
-            else if (left is int)    return (T)(ValueType)(int)    ( (int)   (ValueType)left & ~(int)   (ValueType)right );
-            else if (left is long)   return (T)(ValueType)(long)   ( (long)  (ValueType)left & ~(long)  (ValueType)right );
-            else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left & ~(ushort)(ValueType)right );
-            else if (left is uint)   return (T)(ValueType)(uint)   ( (uint)  (ValueType)left & ~(uint)  (ValueType)right );
-            else if (left is ulong)  return (T)(ValueType)(ulong)  ( (ulong) (ValueType)left & ~(ulong) (ValueType)right );
-            else if (left is byte)   return (T)(ValueType)(byte)   ( (byte)  (ValueType)left & ~(byte)  (ValueType)right );
-            else if (left is sbyte)  return (T)(ValueType)(sbyte)  ( (sbyte) (ValueType)left & ~(sbyte) (ValueType)right );
-            else throw new NotImplementedException();
+            return left & ~ right;
         }
 
-        public static T OnesComplement<T>(T left) where T : struct
+        [RequiresPreviewFeatures]
+        public static T OnesComplement<T>(T left) where T : IBitwiseOperators<T, T, T>
         {
-            unchecked
-            {
-                if      (left is short)  return (T)(ValueType)(short)  ( ~(short) (ValueType)left );
-                else if (left is int)    return (T)(ValueType)(int)    ( ~(int)   (ValueType)left );
-                else if (left is long)   return (T)(ValueType)(long)   ( ~(long)  (ValueType)left );
-                else if (left is ushort) return (T)(ValueType)(ushort) ( ~(ushort)(ValueType)left );
-                else if (left is uint)   return (T)(ValueType)(uint)   ( ~(uint)  (ValueType)left );
-                else if (left is ulong)  return (T)(ValueType)(ulong)  ( ~(ulong) (ValueType)left );
-                else if (left is byte)   return (T)(ValueType)(byte)   ( ~(byte)  (ValueType)left );
-                else if (left is sbyte)  return (T)(ValueType)(sbyte)  ( ~(sbyte) (ValueType)left );
-                else throw new NotImplementedException();
-            }
+            return ~left;
         }
 
         public static float Clamp(float value, float min, float max)
@@ -240,101 +157,48 @@ namespace System.Numerics.Tests
             return value > max ? max : value < min ? min : value;
         }
 
-        public static T Zero<T>() where T : struct
+        [RequiresPreviewFeatures]
+        public static T Zero<T>() where T : struct, INumber<T>
         {
-            if      (typeof(T) == typeof(short))  return  (T)(ValueType)(short)  0;
-            else if (typeof(T) == typeof(int))    return  (T)(ValueType)(int)    0;
-            else if (typeof(T) == typeof(long))   return  (T)(ValueType)(long)   0;
-            else if (typeof(T) == typeof(ushort)) return  (T)(ValueType)(ushort) 0;
-            else if (typeof(T) == typeof(uint))   return  (T)(ValueType)(uint)   0;
-            else if (typeof(T) == typeof(ulong))  return  (T)(ValueType)(ulong)  0;
-            else if (typeof(T) == typeof(byte))   return  (T)(ValueType)(byte)   0;
-            else if (typeof(T) == typeof(sbyte))  return  (T)(ValueType)(sbyte)  0;
-            else if (typeof(T) == typeof(float))  return  (T)(ValueType)(float)  0;
-            else if (typeof(T) == typeof(double)) return  (T)(ValueType)(double) 0;
-            else throw new NotImplementedException();
+            return T.Zero;
         }
 
-        public static T One<T>() where T : struct
+        [RequiresPreviewFeatures]
+        public static T One<T>() where T : struct, INumber<T>
         {
-            if      (typeof(T) == typeof(short))  return  (T)(ValueType)(short)  1;
-            else if (typeof(T) == typeof(int))    return  (T)(ValueType)(int)    1;
-            else if (typeof(T) == typeof(long))   return  (T)(ValueType)(long)   1;
-            else if (typeof(T) == typeof(ushort)) return  (T)(ValueType)(ushort) 1;
-            else if (typeof(T) == typeof(uint))   return  (T)(ValueType)(uint)   1;
-            else if (typeof(T) == typeof(ulong))  return  (T)(ValueType)(ulong)  1;
-            else if (typeof(T) == typeof(byte))   return  (T)(ValueType)(byte)   1;
-            else if (typeof(T) == typeof(sbyte))  return  (T)(ValueType)(sbyte)  1;
-            else if (typeof(T) == typeof(float))  return  (T)(ValueType)(float)  1;
-            else if (typeof(T) == typeof(double)) return  (T)(ValueType)(double) 1;
-            else throw new NotImplementedException();
+            return T.One;
         }
 
-        public static bool GreaterThan<T>(T left, T right) where T : struct
+        [RequiresPreviewFeatures]
+        public static bool GreaterThan<T>(T left, T right) where T : INumber<T>
         {
-            if      (left is short)  return  (short)(ValueType)  left > (short)(ValueType)  right;
-            else if (left is int)    return  (int)(ValueType)    left > (int)(ValueType)    right;
-            else if (left is long)   return  (long)(ValueType)   left > (long)(ValueType)   right;
-            else if (left is ushort) return  (ushort)(ValueType) left > (ushort)(ValueType) right;
-            else if (left is uint)   return  (uint)(ValueType)   left > (uint)(ValueType)   right;
-            else if (left is ulong)  return  (ulong)(ValueType)  left > (ulong)(ValueType)  right;
-            else if (left is byte)   return  (byte)(ValueType)   left > (byte)(ValueType)   right;
-            else if (left is sbyte)  return  (sbyte)(ValueType)  left > (sbyte)(ValueType)  right;
-            else if (left is float)  return  (float)(ValueType)  left > (float)(ValueType)  right;
-            else if (left is double) return  (double)(ValueType) left > (double)(ValueType) right;
-            else throw new NotImplementedException();
+            return left > right;
         }
 
-        public static bool GreaterThanOrEqual<T>(T left, T right) where T : struct
-        {
-            if      (left is short)  return  (short)(ValueType)  left >= (short)(ValueType)  right;
-            else if (left is int)    return  (int)(ValueType)    left >= (int)(ValueType)    right;
-            else if (left is long)   return  (long)(ValueType)   left >= (long)(ValueType)   right;
-            else if (left is ushort) return  (ushort)(ValueType) left >= (ushort)(ValueType) right;
-            else if (left is uint)   return  (uint)(ValueType)   left >= (uint)(ValueType)   right;
-            else if (left is ulong)  return  (ulong)(ValueType)  left >= (ulong)(ValueType)  right;
-            else if (left is byte)   return  (byte)(ValueType)   left >= (byte)(ValueType)   right;
-            else if (left is sbyte)  return  (sbyte)(ValueType)  left >= (sbyte)(ValueType)  right;
-            else if (left is float)  return  (float)(ValueType)  left >= (float)(ValueType)  right;
-            else if (left is double) return  (double)(ValueType) left >= (double)(ValueType) right;
-            else throw new NotImplementedException();
+        [RequiresPreviewFeatures]
+        public static bool GreaterThanOrEqual<T>(T left, T right) where T : INumber<T> 
+        { 
+            return left >= right;
         }
 
-        public static bool LessThan<T>(T left, T right) where T : struct
+        [RequiresPreviewFeatures]
+        public static bool LessThan<T>(T left, T right) where T : INumber<T>
         {
-            if      (left is short)  return  (short)(ValueType)  left < (short)(ValueType)  right;
-            else if (left is int)    return  (int)(ValueType)    left < (int)(ValueType)    right;
-            else if (left is long)   return  (long)(ValueType)   left < (long)(ValueType)   right;
-            else if (left is ushort) return  (ushort)(ValueType) left < (ushort)(ValueType) right;
-            else if (left is uint)   return  (uint)(ValueType)   left < (uint)(ValueType)   right;
-            else if (left is ulong)  return  (ulong)(ValueType)  left < (ulong)(ValueType)  right;
-            else if (left is byte)   return  (byte)(ValueType)   left < (byte)(ValueType)   right;
-            else if (left is sbyte)  return  (sbyte)(ValueType)  left < (sbyte)(ValueType)  right;
-            else if (left is float)  return  (float)(ValueType)  left < (float)(ValueType)  right;
-            else if (left is double) return  (double)(ValueType) left < (double)(ValueType) right;
-            else throw new NotImplementedException();
+            return left < right;
         }
 
-        public static bool LessThanOrEqual<T>(T left, T right) where T : struct
+        [RequiresPreviewFeatures]
+        public static bool LessThanOrEqual<T>(T left, T right) where T : INumber<T>
         {
-            if      (left is short)  return  (short)(ValueType)  left <= (short)(ValueType)  right;
-            else if (left is int)    return  (int)(ValueType)    left <= (int)(ValueType)    right;
-            else if (left is long)   return  (long)(ValueType)   left <= (long)(ValueType)   right;
-            else if (left is ushort) return  (ushort)(ValueType) left <= (ushort)(ValueType) right;
-            else if (left is uint)   return  (uint)(ValueType)   left <= (uint)(ValueType)   right;
-            else if (left is ulong)  return  (ulong)(ValueType)  left <= (ulong)(ValueType)  right;
-            else if (left is byte)   return  (byte)(ValueType)   left <= (byte)(ValueType)   right;
-            else if (left is sbyte)  return  (sbyte)(ValueType)  left <= (sbyte)(ValueType)  right;
-            else if (left is float)  return  (float)(ValueType)  left <= (float)(ValueType)  right;
-            else if (left is double) return  (double)(ValueType) left <= (double)(ValueType) right;
-            else throw new NotImplementedException();
+            return left <= right;
         }
 
-        public static bool AnyEqual<T>(T[] left, T[] right) where T : struct
+        [RequiresPreviewFeatures]
+        public static bool AnyEqual<T>(T[] left, T[] right) where T : INumber<T>
         {
             for (int g = 0; g < left.Length; g++)
             {
-                if (((IEquatable<T>)left[g]).Equals(right[g]))
+                if(left[g] == right[g])
                 {
                     return true;
                 }
@@ -342,11 +206,12 @@ namespace System.Numerics.Tests
             return false;
         }
 
-        public static bool AllEqual<T>(T[] left, T[] right) where T : struct
+        [RequiresPreviewFeatures]
+        public static bool AllEqual<T>(T[] left, T[] right) where T : INumber<T>
         {
             for (int g = 0; g < left.Length; g++)
             {
-                if (!((IEquatable<T>)left[g]).Equals(right[g]))
+                if (left[g] != right[g])
                 {
                     return false;
                 }