Skip to content

Commit

Permalink
fix NaN roundtripping; update dev dependencies; etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroupc committed Jun 29, 2021
1 parent a96d670 commit 3c355d7
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 24 deletions.
1 change: 1 addition & 0 deletions Numbers/Numbers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ licensed under Creative Commons Zero (CC0): https://creativecommons.org/publicdo
Version 1.8.1

- Fix bugs in EFloat string parsing in certain corner cases
- Fix NaN roundtripping with From/ToSingleBits and From/ToDoubleBits

Version 1.8

Expand Down
4 changes: 2 additions & 2 deletions Numbers/PeterO/Numbers/EDecimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ public sealed partial class EDecimal : IComparable<EDecimal>,
lvalue = unchecked((value[0] & 0xffffffffL) | ((long)value[1] << 32));
int flags = (neg ? BigNumberFlags.FlagNegative : 0) | (quiet ?
BigNumberFlags.FlagQuietNaN : BigNumberFlags.FlagSignalingNaN);
return lvalue == 0 ? (quiet ? NaN : SignalingNaN) :
return (lvalue == 0 && !neg) ? (quiet ? NaN : SignalingNaN) :
new EDecimal(
FastIntegerFixed.FromInt64(lvalue),
FastIntegerFixed.Zero,
Expand Down Expand Up @@ -1186,7 +1186,7 @@ public sealed partial class EDecimal : IComparable<EDecimal>,
value = (neg ? BigNumberFlags.FlagNegative : 0) |
(quiet ? BigNumberFlags.FlagQuietNaN :
BigNumberFlags.FlagSignalingNaN);
return valueFpMantissa == 0 ? (quiet ? NaN : SignalingNaN) :
return (valueFpMantissa == 0 && !neg) ? (quiet ? NaN : SignalingNaN) :
new EDecimal(
FastIntegerFixed.FromInt32(valueFpMantissa),
FastIntegerFixed.Zero,
Expand Down
4 changes: 2 additions & 2 deletions Numbers/PeterO/Numbers/EFloat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ public sealed partial class EFloat : IComparable<EFloat>,
// Treat high bit of mantissa as quiet/signaling bit
bool quiet = ((dblBits >> 32) & 0x80000) != 0;
lvalue = dblBits & ((1L << 51) - 1);
if (lvalue == 0) {
if (lvalue == 0 && !neg) {
return quiet ? NaN : SignalingNaN;
}
int flags = (neg ? BigNumberFlags.FlagNegative : 0) |
Expand Down Expand Up @@ -688,7 +688,7 @@ public sealed partial class EFloat : IComparable<EFloat>,
bigmant = (EInteger)valueFpMantissa;
value = (neg ? BigNumberFlags.FlagNegative : 0) | (quiet ?
BigNumberFlags.FlagQuietNaN : BigNumberFlags.FlagSignalingNaN);
if (bigmant.IsZero) {
if (bigmant.IsZero && !neg) {
return quiet ? NaN : SignalingNaN;
}
return CreateWithFlags(
Expand Down
8 changes: 4 additions & 4 deletions Numbers20/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id='StyleCop.Analyzers' version='1.2.0-beta.333' targetFramework='net20' developmentDependency='true'>
</package>
<package id='Microsoft.CodeAnalysis.NetAnalyzers' version='5.0.3' targetFramework='net20' developmentDependency='true'/>
<package id="Microsoft.CodeAnalysis.NetAnalyzers" version="5.0.3" targetFramework="net20" developmentDependency="true" />
<package id="StyleCop.Analyzers" version="1.2.0-beta.354" targetFramework="net20" developmentDependency="true"></package>
<package id="StyleCop.Analyzers.Unstable" version="1.2.0.354" targetFramework="net20" developmentDependency="true" />
</packages>
8 changes: 4 additions & 4 deletions Numbers40/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id='StyleCop.Analyzers' version='1.2.0-beta.333' targetFramework='net40' developmentDependency='true'>
</package>
<package id='Microsoft.CodeAnalysis.NetAnalyzers' version='5.0.3' targetFramework='net40' developmentDependency='true'/>
<package id="Microsoft.CodeAnalysis.NetAnalyzers" version="5.0.3" targetFramework="net40" developmentDependency="true" />
<package id="StyleCop.Analyzers" version="1.2.0-beta.354" targetFramework="net40" developmentDependency="true"></package>
<package id="StyleCop.Analyzers.Unstable" version="1.2.0.354" targetFramework="net40" developmentDependency="true" />
</packages>
32 changes: 32 additions & 0 deletions Test/EDecimalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,38 @@ public class EDecimalTest {
}
}

[Test]
public void TestFromSingleBitsNaN() {
int bits = unchecked((int)0xffc00000);
Assert.AreEqual(bits, EDecimal.FromSingleBits(bits).ToSingleBits());
bits = 0x7fc00000;
Assert.AreEqual(bits, EDecimal.FromSingleBits(bits).ToSingleBits());
bits = unchecked((int)0xffc00000);
Assert.AreEqual(bits, EFloat.FromSingleBits(bits).ToSingleBits());
bits = 0x7fc00000;
Assert.AreEqual(bits, EFloat.FromSingleBits(bits).ToSingleBits());
bits = unchecked((int)0xffc00000);
Assert.AreEqual(bits, ERational.FromSingleBits(bits).ToSingleBits());
bits = 0x7fc00000;
Assert.AreEqual(bits, ERational.FromSingleBits(bits).ToSingleBits());
}

[Test]
public void TestFromDoubleBitsNaN() {
long lbits = unchecked((long)0xfff8000000000000);
Assert.AreEqual(lbits, EDecimal.FromDoubleBits(lbits).ToDoubleBits());
lbits = 0x7ff8000000000000L;
Assert.AreEqual(lbits, EDecimal.FromDoubleBits(lbits).ToDoubleBits());
lbits = unchecked((long)0xfff8000000000000);
Assert.AreEqual(lbits, EFloat.FromDoubleBits(lbits).ToDoubleBits());
lbits = 0x7ff8000000000000L;
Assert.AreEqual(lbits, EFloat.FromDoubleBits(lbits).ToDoubleBits());
lbits = unchecked((long)0xfff8000000000000);
Assert.AreEqual(lbits, ERational.FromDoubleBits(lbits).ToDoubleBits());
lbits = 0x7ff8000000000000L;
Assert.AreEqual(lbits, ERational.FromDoubleBits(lbits).ToDoubleBits());
}

[Test]
public void TestCompareToBinarySpecific1A() {
EFloat ef;
Expand Down
2 changes: 1 addition & 1 deletion Test/EFloatTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ public class EFloatTest {
Assert.Fail(line);
}
string f64 = line.Substring(4 + 1 + 8 + 1, 16);
if (line[4+1+8 + 17] != ' ') {
if (line[4 + 26] != ' ') {
Assert.Fail(line);
}
string str = line.Substring(4 + 1 + 8 + 1 + 16 + 1);
Expand Down
10 changes: 5 additions & 5 deletions Test20/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package developmentDependency='true' id='NUnitTestAdapter.WithFramework' targetFramework='net20' version='2.0.0'/>
<package id='StyleCop.Analyzers' version='1.2.0-beta.333' targetFramework='net20' developmentDependency='true'>
</package>
<package id='Microsoft.CodeAnalysis.NetAnalyzers' version='5.0.3' targetFramework='net20' developmentDependency='true'/>
<package id="Microsoft.CodeAnalysis.NetAnalyzers" version="5.0.3" targetFramework="net20" developmentDependency="true" />
<package developmentDependency="true" id="NUnitTestAdapter.WithFramework" targetFramework="net20" version="2.0.0" />
<package id="StyleCop.Analyzers" version="1.2.0-beta.354" targetFramework="net20" developmentDependency="true"></package>
<package id="StyleCop.Analyzers.Unstable" version="1.2.0.354" targetFramework="net20" developmentDependency="true" />
</packages>
139 changes: 138 additions & 1 deletion Test40/Test40.csproj
Original file line number Diff line number Diff line change
@@ -1 +1,138 @@
<?xml version='1.0' encoding='UTF-8'?><Project DefaultTargets='Build' ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'><Import Condition='Exists(&apos;..\packages\NUnit.3.12.0\build\NUnit.props&apos;)' Project='..\packages\NUnit.3.12.0\build\NUnit.props'/><PropertyGroup><Configuration Condition=' &apos;$(Configuration)&apos; == &apos;&apos; '>Debug</Configuration><Platform Condition=' &apos;$(Platform)&apos; == &apos;&apos; '>AnyCPU</Platform><ProjectGuid>{00EB31B6-A805-4EFB-A64B-9F8176B2A1CC}</ProjectGuid><OutputType>Exe</OutputType><AssemblyName>Test40</AssemblyName><CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet></PropertyGroup><PropertyGroup Condition=' &apos;$(Configuration)&apos;==&apos;Debug&apos; '><DebugSymbols>true</DebugSymbols><DebugType>full</DebugType><Optimize>false</Optimize><OutputPath>bin\Debug</OutputPath><DefineConstants>DEBUG;NET40</DefineConstants><ErrorReport>prompt</ErrorReport><WarningLevel>4</WarningLevel><ExternalConsole>true</ExternalConsole><CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet></PropertyGroup><PropertyGroup Condition=' &apos;$(Configuration)&apos;==&apos;Release&apos; '><Optimize>true</Optimize><OutputPath>bin\Release</OutputPath><ErrorReport>prompt</ErrorReport><DefineConstants>NET40</DefineConstants><WarningLevel>4</WarningLevel><ExternalConsole>true</ExternalConsole><CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet></PropertyGroup><ItemGroup><Reference Include='System'/><Reference Include='System.Numerics'/><PackageReference Include='NUnit'><Version>3.12.0</Version></PackageReference><PackageReference Include='StyleCop.Analyzers'><Version>1.1.118</Version></PackageReference><PackageReference Include='Microsoft.CodeAnalysis.NetAnalyzers'><Version>5.0.3</Version></PackageReference><Compile Include='../Test/EDecimalTest.cs'><Link>EDecimalTest.cs</Link></Compile><Compile Include='../Test/EContextTest.cs'><Link>EContextTest.cs</Link></Compile><Compile Include='../Test/IRandomGenExtended.cs'><Link>IRandomGenExtended.cs</Link></Compile><Compile Include='../Test/XorShift128Plus.cs'><Link>XorShift128Plus.cs</Link></Compile><AdditionalFiles Include='../Test/stylecop.json'><Link>stylecop.json</Link></AdditionalFiles><Compile Include='../Test/RandomObjects.cs'><Link>RandomObjects.cs</Link></Compile><Compile Include='../Test/AppResources.cs'><Link>AppResources.cs</Link></Compile><Compile Include='../Test/TestCommon.cs'><Link>TestCommon.cs</Link></Compile><Compile Include='../Test/ETrapExceptionTest.cs'><Link>ETrapExceptionTest.cs</Link></Compile><Compile Include='../Test/SevenBitEncoded.cs'><Link>SevenBitEncoded.cs</Link></Compile><Compile Include='../Test/EIntegerTest.cs'><Link>EIntegerTest.cs</Link></Compile><Compile Include='../Test/RandomGenerator.cs'><Link>RandomGenerator.cs</Link></Compile><Compile Include='../Test/ExtraTest.cs'><Link>ExtraTest.cs</Link></Compile><Compile Include='../Test/StringAndBigInt.cs'><Link>StringAndBigInt.cs</Link></Compile><Compile Include='../Test/DecTestUtil.cs'><Link>DecTestUtil.cs</Link></Compile><EmbeddedResource Include='../Test/Resources.restext'><Link>Resources.restext</Link><LogicalName>Resources.resources</LogicalName></EmbeddedResource><Compile Include='../Test/DecimalTest.cs'><Link>DecimalTest.cs</Link></Compile><Compile Include='../Test/Runner.cs'><Link>Runner.cs</Link></Compile><Compile Include='../Test/ExtensiveTest.cs'><Link>ExtensiveTest.cs</Link></Compile><Compile Include='../Test/ERationalTest.cs'><Link>ERationalTest.cs</Link></Compile><Compile Include='../Test/IRandomGen.cs'><Link>IRandomGen.cs</Link></Compile><Compile Include='../Test/EFloatTest.cs'><Link>EFloatTest.cs</Link></Compile><Compile Include='Properties/AssemblyInfo.cs'/><AdditionalFiles Include='stylecop.json'></AdditionalFiles><AdditionalFiles Include='rules.ruleset'></AdditionalFiles></ItemGroup><ItemGroup><ProjectReference Include='..\Numbers40\Numbers40.csproj'><Project>{D7E09F55-3156-44B0-87D9-1BABCBB398D9}</Project><Name>Test40</Name></ProjectReference></ItemGroup><Import Project='$(MSBuildToolsPath)\Microsoft.CSharp.targets'/><PropertyGroup><TargetFrameworkVersion>v4.0</TargetFrameworkVersion><RuntimeIdentifiers>win</RuntimeIdentifiers></PropertyGroup></Project>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="../packages/NUnit.3.13.2/build/NUnit.props" Condition="Exists('../packages/NUnit.3.13.2/build/NUnit.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{00EB31B6-A805-4EFB-A64B-9F8176B2A1CC}</ProjectGuid>
<OutputType>Exe</OutputType>
<AssemblyName>Test40</AssemblyName>
<CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;NET40</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)'=='Release' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<DefineConstants>NET40</DefineConstants>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.13.2.0, Culture=neutral, PublicKeyToken=2638cd05610744eb">
<HintPath>../packages/NUnit.3.13.2/lib/net40/nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Numerics" />
<PackageReference Include="NUnit">
<Version>3.12.0</Version>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers">
<Version>5.0.3</Version>
</PackageReference>
<Compile Include="../Test/EDecimalTest.cs">
<Link>EDecimalTest.cs</Link>
</Compile>
<Compile Include="../Test/EContextTest.cs">
<Link>EContextTest.cs</Link>
</Compile>
<Compile Include="../Test/IRandomGenExtended.cs">
<Link>IRandomGenExtended.cs</Link>
</Compile>
<Compile Include="../Test/XorShift128Plus.cs">
<Link>XorShift128Plus.cs</Link>
</Compile>
<AdditionalFiles Include="../Test/stylecop.json">
<Link>stylecop.json</Link>
</AdditionalFiles>
<Compile Include="../Test/RandomObjects.cs">
<Link>RandomObjects.cs</Link>
</Compile>
<Compile Include="../Test/AppResources.cs">
<Link>AppResources.cs</Link>
</Compile>
<Compile Include="../Test/TestCommon.cs">
<Link>TestCommon.cs</Link>
</Compile>
<Compile Include="../Test/ETrapExceptionTest.cs">
<Link>ETrapExceptionTest.cs</Link>
</Compile>
<Compile Include="../Test/SevenBitEncoded.cs">
<Link>SevenBitEncoded.cs</Link>
</Compile>
<Compile Include="../Test/EIntegerTest.cs">
<Link>EIntegerTest.cs</Link>
</Compile>
<Compile Include="../Test/RandomGenerator.cs">
<Link>RandomGenerator.cs</Link>
</Compile>
<Compile Include="../Test/ExtraTest.cs">
<Link>ExtraTest.cs</Link>
</Compile>
<Compile Include="../Test/StringAndBigInt.cs">
<Link>StringAndBigInt.cs</Link>
</Compile>
<Compile Include="../Test/DecTestUtil.cs">
<Link>DecTestUtil.cs</Link>
</Compile>
<EmbeddedResource Include="../Test/Resources.restext">
<Link>Resources.restext</Link>
<LogicalName>Resources.resources</LogicalName>
</EmbeddedResource>
<Compile Include="../Test/DecimalTest.cs">
<Link>DecimalTest.cs</Link>
</Compile>
<Compile Include="../Test/Runner.cs">
<Link>Runner.cs</Link>
</Compile>
<Compile Include="../Test/ExtensiveTest.cs">
<Link>ExtensiveTest.cs</Link>
</Compile>
<Compile Include="../Test/ERationalTest.cs">
<Link>ERationalTest.cs</Link>
</Compile>
<Compile Include="../Test/IRandomGen.cs">
<Link>IRandomGen.cs</Link>
</Compile>
<Compile Include="../Test/EFloatTest.cs">
<Link>EFloatTest.cs</Link>
</Compile>
<Compile Include="Properties/AssemblyInfo.cs" />
<AdditionalFiles Include="stylecop.json">
</AdditionalFiles>
<AdditionalFiles Include="rules.ruleset">
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Numbers40\Numbers40.csproj">
<Project>{D7E09F55-3156-44B0-87D9-1BABCBB398D9}</Project>
<Name>Test40</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<RuntimeIdentifiers>win</RuntimeIdentifiers>
</PropertyGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('../packages/NUnit.3.13.2/build/NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '../packages/NUnit.3.13.2/build/NUnit.props'))" />
</Target>
</Project>
10 changes: 5 additions & 5 deletions Test40/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id='NUnit' targetFramework='net40' version='3.12.0'/>
<package id='StyleCop.Analyzers' version='1.2.0-beta.333' targetFramework='net40' developmentDependency='true'>
</package>
<package id='Microsoft.CodeAnalysis.NetAnalyzers' version='5.0.3' targetFramework='net40' developmentDependency='true'/>
<package id="Microsoft.CodeAnalysis.NetAnalyzers" version="5.0.3" targetFramework="net40" developmentDependency="true" />
<package id="NUnit" targetFramework="net40" version="3.13.2" />
<package id="StyleCop.Analyzers" version="1.2.0-beta.354" targetFramework="net40" developmentDependency="true"></package>
<package id="StyleCop.Analyzers.Unstable" version="1.2.0.354" targetFramework="net40" developmentDependency="true" />
</packages>

0 comments on commit 3c355d7

Please sign in to comment.