From 6425e4ef11e8a7e2e90a5b0cb0bcba6ec7a685fc Mon Sep 17 00:00:00 2001 From: Don Cross Date: Sun, 5 Jun 2022 10:07:35 -0400 Subject: [PATCH] C#: More benefits from using netstandard2.0. Now that I have retargeted astronomy.csproj from net5.0 to netstandard2.0, there are a couple of other little improvements that are now possible: 1. In my manual Framework 4 test project, instead of directly pulling in the source file astronomy.cs, add astronomy.csproj as a project reference. This demonstrates that the same binary astronomy.dll works in both Framework and Core. 2. Now there is no need/use for conditional compilation directives in the Astronomy.CubeRoot function. Instead, always use my own implementation since the Math.Cbrt function is never available. From a testing standpoint, this was probably the better option all along. --- .../framework4/AstronomyTest/AstronomyTest.csproj | 9 ++++++--- .../dotnet/framework4/AstronomyTest/AstronomyTest.sln | 6 ++++++ generate/dotnet/framework4/README.md | 5 ++++- generate/template/astronomy.cs | 10 ++++------ source/csharp/astronomy.cs | 10 ++++------ 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/generate/dotnet/framework4/AstronomyTest/AstronomyTest.csproj b/generate/dotnet/framework4/AstronomyTest/AstronomyTest.csproj index 6db19b3b..867b9d74 100644 --- a/generate/dotnet/framework4/AstronomyTest/AstronomyTest.csproj +++ b/generate/dotnet/framework4/AstronomyTest/AstronomyTest.csproj @@ -43,14 +43,17 @@ - - astronomy.cs - + + + {7c3fb2a1-2996-4ad0-9d47-52a4227ea78f} + astronomy + + \ No newline at end of file diff --git a/generate/dotnet/framework4/AstronomyTest/AstronomyTest.sln b/generate/dotnet/framework4/AstronomyTest/AstronomyTest.sln index 1ca86883..62b584f3 100644 --- a/generate/dotnet/framework4/AstronomyTest/AstronomyTest.sln +++ b/generate/dotnet/framework4/AstronomyTest/AstronomyTest.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.32106.194 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AstronomyTest", "AstronomyTest.csproj", "{0611FB45-451F-4770-9864-1F34A4609B3D}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "astronomy", "..\..\..\..\source\csharp\astronomy.csproj", "{7C3FB2A1-2996-4AD0-9D47-52A4227EA78F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {0611FB45-451F-4770-9864-1F34A4609B3D}.Debug|Any CPU.Build.0 = Debug|Any CPU {0611FB45-451F-4770-9864-1F34A4609B3D}.Release|Any CPU.ActiveCfg = Release|Any CPU {0611FB45-451F-4770-9864-1F34A4609B3D}.Release|Any CPU.Build.0 = Release|Any CPU + {7C3FB2A1-2996-4AD0-9D47-52A4227EA78F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7C3FB2A1-2996-4AD0-9D47-52A4227EA78F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7C3FB2A1-2996-4AD0-9D47-52A4227EA78F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7C3FB2A1-2996-4AD0-9D47-52A4227EA78F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/generate/dotnet/framework4/README.md b/generate/dotnet/framework4/README.md index 8f5d5597..9de4deb3 100644 --- a/generate/dotnet/framework4/README.md +++ b/generate/dotnet/framework4/README.md @@ -1,6 +1,9 @@ # .NET Framework 4+ -Astronomy Engine officially supports dotnet core (.NET 5+). +The C# version of Astronomy Engine is targeted to +[.NET Standard 2.0](https://docs.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0). +Therefore, it supports .NET Framework 4+ and .NET Core 5+. + Currently I do all unit testing and development under .NET 6. However, I make an effort to maintain backward compatibility with .NET Framework 4+, although issues may slip through. diff --git a/generate/template/astronomy.cs b/generate/template/astronomy.cs index 32b8f99d..21530d86 100644 --- a/generate/template/astronomy.cs +++ b/generate/template/astronomy.cs @@ -8030,12 +8030,11 @@ $ASTRO_IAU_DATA() private static double CubeRoot(double x) { + // Astronomy Engine is targeted at .NET Standard 2.0. + // That means it supports the older Framework 4+ platform + // as well as .NET Core 5+. // .NET Core has a Math.Cbrt function, but .NET Framework doesn't. -#if NET - // Use the standard Math.Cbrt where available. - return Math.Cbrt(x); -#else - // Provide a substitute cube root function when Math.Cbrt isn't available. + // Therefore, I have to implement my own cube root function. if (x < 0.0) return -CubeRoot(-x); @@ -8044,7 +8043,6 @@ $ASTRO_IAU_DATA() return 0.0; return Math.Pow(x, (1.0 / 3.0)); -#endif } /// diff --git a/source/csharp/astronomy.cs b/source/csharp/astronomy.cs index 94c22a6d..e33d62bc 100644 --- a/source/csharp/astronomy.cs +++ b/source/csharp/astronomy.cs @@ -9242,12 +9242,11 @@ namespace CosineKitty private static double CubeRoot(double x) { + // Astronomy Engine is targeted at .NET Standard 2.0. + // That means it supports the older Framework 4+ platform + // as well as .NET Core 5+. // .NET Core has a Math.Cbrt function, but .NET Framework doesn't. -#if NET - // Use the standard Math.Cbrt where available. - return Math.Cbrt(x); -#else - // Provide a substitute cube root function when Math.Cbrt isn't available. + // Therefore, I have to implement my own cube root function. if (x < 0.0) return -CubeRoot(-x); @@ -9256,7 +9255,6 @@ namespace CosineKitty return 0.0; return Math.Pow(x, (1.0 / 3.0)); -#endif } ///