This commit is contained in:
@@ -3,10 +3,9 @@ namespace Just.PreciseMath;
|
||||
/// <summary>
|
||||
/// Represents higher precision floating point type
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Constructs new DoubleDouble from given low and high components
|
||||
/// </remarks>
|
||||
public readonly struct DoubleDouble : IEquatable<DoubleDouble>, IEqualityOperators<DoubleDouble, DoubleDouble, bool>
|
||||
public readonly struct DoubleDouble :
|
||||
IEquatable<DoubleDouble>,
|
||||
IEqualityOperators<DoubleDouble, DoubleDouble, bool>
|
||||
{
|
||||
internal readonly double _high;
|
||||
internal readonly double _low;
|
||||
@@ -18,6 +17,14 @@ public readonly struct DoubleDouble : IEquatable<DoubleDouble>, IEqualityOperato
|
||||
_low = low;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs new DoubleDouble from a given double.
|
||||
/// </summary>
|
||||
/// <param name="high">Initial high component</param>
|
||||
public DoubleDouble(double high) : this(high, 0.0)
|
||||
{
|
||||
}
|
||||
|
||||
#region Static constants
|
||||
/// <summary>
|
||||
/// Represents a value that is not a number (NaN).
|
||||
@@ -31,6 +38,18 @@ public readonly struct DoubleDouble : IEquatable<DoubleDouble>, IEqualityOperato
|
||||
/// Represents a zero value.
|
||||
/// </summary>
|
||||
public static DoubleDouble Zero => new();
|
||||
/// <summary>
|
||||
/// Represents the ratio of the circumference of a circle to its diameter, specified by the constant, π.
|
||||
/// </summary>
|
||||
public static DoubleDouble PI => new(3.141592653589793, 1.2246467991473532e-16);
|
||||
/// <summary>
|
||||
/// Represents the natural logarithmic base, specified by the constant, e.
|
||||
/// </summary>
|
||||
public static DoubleDouble E => new(2.718281828459045, 1.4456468917292502e-16);
|
||||
/// <summary>
|
||||
/// Represents the natural logarithm of value 2.
|
||||
/// </summary>
|
||||
public static DoubleDouble LN2 => new(0.6931471805599453, 2.3190468138462996e-17);
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace Just.PreciseMath;
|
||||
|
||||
internal static class PreciseMathHelper
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static (double Res, double Err) TwoAdd(double a, double b)
|
||||
{
|
||||
double r = a + b;
|
||||
double t = r - a;
|
||||
|
||||
return (r, (a - (r - t)) + (b - t));
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static (double Res, double Err) TwoQuickAdd(double a, double b)
|
||||
{
|
||||
double r = a + b;
|
||||
|
||||
return (r, b - (r - a));
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static (double Res, double Err) TwoSubstract(double a, double b)
|
||||
{
|
||||
double r = a - b;
|
||||
double t = r - a;
|
||||
|
||||
return (r, (a - (r - t)) - (b + t));
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static (double Res, double Err) TwoMultiply(double a, double b)
|
||||
{
|
||||
double r = a * b;
|
||||
|
||||
return (r, Math.FusedMultiplyAdd(a, b, -r));
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static (double Res, double Err) TwoSuare(double a)
|
||||
{
|
||||
double r = a * a;
|
||||
|
||||
return (r, Math.FusedMultiplyAdd(a, a, -r));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user