Skip to content

Commit

Permalink
Updating System.Runtime.InteropServices.NFloat to support generic math (
Browse files Browse the repository at this point in the history
#68141)

* Updating NFloat to implement IBinaryFloatingPointIeee754 and IMinMaxValue

* Adding tests for the NFloat generic math support

* Fixing NFloat to expose the APIs for getting the exponent and significand

* Fix the NFloat.GetSignificandByteCount implementation
  • Loading branch information
tannergooding committed Apr 19, 2022
1 parent 544f720 commit 4479fa6
Show file tree
Hide file tree
Showing 10 changed files with 2,896 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Globalization;
using System.Numerics;

namespace System.Tests
namespace System
{
public static class AdditionOperatorsHelper<TSelf, TOther, TResult>
where TSelf : IAdditionOperators<TSelf, TOther, TResult>
Expand Down
18 changes: 9 additions & 9 deletions src/libraries/System.Private.CoreLib/src/System/Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ public readonly struct Double
public const double NaN = (double)0.0 / (double)0.0;

/// <summary>Represents the additive identity (0).</summary>
private const double AdditiveIdentity = 0.0;
internal const double AdditiveIdentity = 0.0;

/// <summary>Represents the multiplicative identity (1).</summary>
private const double MultiplicativeIdentity = 1.0;
internal const double MultiplicativeIdentity = 1.0;

/// <summary>Represents the number one (1).</summary>
private const double One = 1.0;
internal const double One = 1.0;

/// <summary>Represents the number zero (0).</summary>
private const double Zero = 0.0;
internal const double Zero = 0.0;

/// <summary>Represents the number negative one (-1).</summary>
private const double NegativeOne = -1.0;
internal const double NegativeOne = -1.0;

/// <summary>Represents the number negative zero (-0).</summary>
public const double NegativeZero = -0.0;
Expand Down Expand Up @@ -105,7 +105,7 @@ public readonly struct Double
internal const ulong MinTrailingSignificand = 0x0000_0000_0000_0000;
internal const ulong MaxTrailingSignificand = 0x000F_FFFF_FFFF_FFFF;

private ushort BiasedExponent
internal ushort BiasedExponent
{
get
{
Expand All @@ -114,23 +114,23 @@ private ushort BiasedExponent
}
}

private short Exponent
internal short Exponent
{
get
{
return (short)(BiasedExponent - ExponentBias);
}
}

private ulong Significand
internal ulong Significand
{
get
{
return TrailingSignificand | ((BiasedExponent != 0) ? (1UL << BiasedExponentShift) : 0UL);
}
}

private ulong TrailingSignificand
internal ulong TrailingSignificand
{
get
{
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Private.CoreLib/src/System/Half.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal Half(ushort value)

private Half(bool sign, ushort exp, ushort sig) => _value = (ushort)(((sign ? 1 : 0) << SignShift) + (exp << BiasedExponentShift) + sig);

private byte BiasedExponent
internal byte BiasedExponent
{
get
{
Expand All @@ -109,23 +109,23 @@ private byte BiasedExponent
}
}

private sbyte Exponent
internal sbyte Exponent
{
get
{
return (sbyte)(BiasedExponent - ExponentBias);
}
}

private ushort Significand
internal ushort Significand
{
get
{
return (ushort)(TrailingSignificand | ((BiasedExponent != 0) ? (1U << BiasedExponentShift) : 0U));
}
}

private ushort TrailingSignificand
internal ushort TrailingSignificand
{
get
{
Expand Down

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/libraries/System.Private.CoreLib/src/System/Single.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ public readonly struct Single
public const float NaN = (float)0.0 / (float)0.0;

/// <summary>Represents the additive identity (0).</summary>
private const float AdditiveIdentity = 0.0f;
internal const float AdditiveIdentity = 0.0f;

/// <summary>Represents the multiplicative identity (1).</summary>
private const float MultiplicativeIdentity = 1.0f;
internal const float MultiplicativeIdentity = 1.0f;

/// <summary>Represents the number one (1).</summary>
private const float One = 1.0f;
internal const float One = 1.0f;

/// <summary>Represents the number zero (0).</summary>
private const float Zero = 0.0f;
internal const float Zero = 0.0f;

/// <summary>Represents the number negative one (-1).</summary>
private const float NegativeOne = -1.0f;
internal const float NegativeOne = -1.0f;

/// <summary>Represents the number negative zero (-0).</summary>
public const float NegativeZero = -0.0f;
Expand Down Expand Up @@ -104,7 +104,7 @@ public readonly struct Single
internal const uint MinTrailingSignificand = 0x0000_0000;
internal const uint MaxTrailingSignificand = 0x007F_FFFF;

private byte BiasedExponent
internal byte BiasedExponent
{
get
{
Expand All @@ -113,23 +113,23 @@ private byte BiasedExponent
}
}

private sbyte Exponent
internal sbyte Exponent
{
get
{
return (sbyte)(BiasedExponent - ExponentBias);
}
}

private uint Significand
internal uint Significand
{
get
{
return TrailingSignificand | ((BiasedExponent != 0) ? (1U << BiasedExponentShift) : 0U);
}
}

private uint TrailingSignificand
internal uint TrailingSignificand
{
get
{
Expand Down
Loading

0 comments on commit 4479fa6

Please sign in to comment.