mirror of
https://github.com/cosinekitty/astronomy.git
synced 2026-05-19 14:27:52 -04:00
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.
This commit is contained in:
@@ -43,14 +43,17 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\..\source\csharp\astronomy.cs">
|
||||
<Link>astronomy.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\source\csharp\astronomy.csproj">
|
||||
<Project>{7c3fb2a1-2996-4ad0-9d47-52a4227ea78f}</Project>
|
||||
<Name>astronomy</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user