Skip to content
968 changes: 948 additions & 20 deletions src/libraries/System.Private.CoreLib/src/System/Number.DecimalIeee754.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,48 @@ bool IFloatingPoint<Decimal128>.TryWriteSignificandLittleEndian(Span<byte> desti
return false;
}

//
// IFloatingPointIeee754
//

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.BitDecrement(TSelf)" />
public static Decimal128 BitDecrement(Decimal128 x) => new Decimal128(Number.BitDecrementDecimalIeee754<Decimal128, UInt128>(new UInt128(x._upper, x._lower)));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.BitIncrement(TSelf)" />
public static Decimal128 BitIncrement(Decimal128 x) => new Decimal128(Number.BitIncrementDecimalIeee754<Decimal128, UInt128>(new UInt128(x._upper, x._lower)));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.FusedMultiplyAdd(TSelf, TSelf, TSelf)" />
public static Decimal128 FusedMultiplyAdd(Decimal128 left, Decimal128 right, Decimal128 addend) => new Decimal128(Number.FusedMultiplyAddDecimalIeee754<Decimal128, UInt128>(new UInt128(left._upper, left._lower), new UInt128(right._upper, right._lower), new UInt128(addend._upper, addend._lower)));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.Ieee754Remainder(TSelf, TSelf)" />
public static Decimal128 Ieee754Remainder(Decimal128 left, Decimal128 right) => new Decimal128(Number.Ieee754RemainderDecimalIeee754<Decimal128, UInt128>(new UInt128(left._upper, left._lower), new UInt128(right._upper, right._lower)));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.ILogB(TSelf)" />
public static int ILogB(Decimal128 x) => Number.ILogBDecimalIeee754<Decimal128, UInt128>(new UInt128(x._upper, x._lower));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.ScaleB(TSelf, int)" />
public static Decimal128 ScaleB(Decimal128 x, int n) => new Decimal128(Number.ScaleBDecimalIeee754<Decimal128, UInt128>(new UInt128(x._upper, x._lower), n));

/// <inheritdoc cref="IRootFunctions{TSelf}.Sqrt(TSelf)" />
public static Decimal128 Sqrt(Decimal128 x) => new Decimal128(Number.SqrtDecimalIeee754<Decimal128, UInt128>(new UInt128(x._upper, x._lower)));

/// <summary>Adjusts a value to the quantum (exponent) of another value, rounding to nearest with ties to even.</summary>
/// <param name="x">The value whose quantum is adjusted.</param>
/// <param name="y">The value that provides the target quantum.</param>
/// <returns><paramref name="x" /> expressed with the quantum of <paramref name="y" />, or NaN when the value cannot be represented at that quantum.</returns>
public static Decimal128 Quantize(Decimal128 x, Decimal128 y) => new Decimal128(Number.QuantizeDecimalIeee754<Decimal128, UInt128>(new UInt128(x._upper, x._lower), new UInt128(y._upper, y._lower)));

/// <summary>Computes the quantum of a value: one unit in the last place sharing its exponent.</summary>
/// <param name="x">The value whose quantum is returned.</param>
/// <returns>The quantum of <paramref name="x" />.</returns>
public static Decimal128 Quantum(Decimal128 x) => new Decimal128(Number.QuantumDecimalIeee754<Decimal128, UInt128>(new UInt128(x._upper, x._lower)));

/// <summary>Determines whether two values have the same quantum (exponent).</summary>
/// <param name="x">The first value to compare.</param>
/// <param name="y">The second value to compare.</param>
/// <returns><c>true</c> if <paramref name="x" /> and <paramref name="y" /> have the same quantum; otherwise, <c>false</c>.</returns>
public static bool SameQuantum(Decimal128 x, Decimal128 y) => Number.SameQuantumDecimalIeee754<Decimal128, UInt128>(new UInt128(x._upper, x._lower), new UInt128(y._upper, y._lower));

/// <summary>Computes the absolute of a value.</summary>
/// <param name="value">The value for which to get its absolute.</param>
/// <returns>The absolute of <paramref name="value" />.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,48 @@ bool IFloatingPoint<Decimal32>.TryWriteSignificandLittleEndian(Span<byte> destin
return false;
}

//
// IFloatingPointIeee754
//

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.BitDecrement(TSelf)" />
public static Decimal32 BitDecrement(Decimal32 x) => new Decimal32(Number.BitDecrementDecimalIeee754<Decimal32, uint>(x._value));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.BitIncrement(TSelf)" />
public static Decimal32 BitIncrement(Decimal32 x) => new Decimal32(Number.BitIncrementDecimalIeee754<Decimal32, uint>(x._value));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.FusedMultiplyAdd(TSelf, TSelf, TSelf)" />
public static Decimal32 FusedMultiplyAdd(Decimal32 left, Decimal32 right, Decimal32 addend) => new Decimal32(Number.FusedMultiplyAddDecimalIeee754<Decimal32, uint>(left._value, right._value, addend._value));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.Ieee754Remainder(TSelf, TSelf)" />
public static Decimal32 Ieee754Remainder(Decimal32 left, Decimal32 right) => new Decimal32(Number.Ieee754RemainderDecimalIeee754<Decimal32, uint>(left._value, right._value));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.ILogB(TSelf)" />
public static int ILogB(Decimal32 x) => Number.ILogBDecimalIeee754<Decimal32, uint>(x._value);

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.ScaleB(TSelf, int)" />
public static Decimal32 ScaleB(Decimal32 x, int n) => new Decimal32(Number.ScaleBDecimalIeee754<Decimal32, uint>(x._value, n));

/// <inheritdoc cref="IRootFunctions{TSelf}.Sqrt(TSelf)" />
public static Decimal32 Sqrt(Decimal32 x) => new Decimal32(Number.SqrtDecimalIeee754<Decimal32, uint>(x._value));

/// <summary>Adjusts a value to the quantum (exponent) of another value, rounding to nearest with ties to even.</summary>
/// <param name="x">The value whose quantum is adjusted.</param>
/// <param name="y">The value that provides the target quantum.</param>
/// <returns><paramref name="x" /> expressed with the quantum of <paramref name="y" />, or NaN when the value cannot be represented at that quantum.</returns>
public static Decimal32 Quantize(Decimal32 x, Decimal32 y) => new Decimal32(Number.QuantizeDecimalIeee754<Decimal32, uint>(x._value, y._value));

/// <summary>Computes the quantum of a value: one unit in the last place sharing its exponent.</summary>
/// <param name="x">The value whose quantum is returned.</param>
/// <returns>The quantum of <paramref name="x" />.</returns>
public static Decimal32 Quantum(Decimal32 x) => new Decimal32(Number.QuantumDecimalIeee754<Decimal32, uint>(x._value));

/// <summary>Determines whether two values have the same quantum (exponent).</summary>
/// <param name="x">The first value to compare.</param>
/// <param name="y">The second value to compare.</param>
/// <returns><c>true</c> if <paramref name="x" /> and <paramref name="y" /> have the same quantum; otherwise, <c>false</c>.</returns>
public static bool SameQuantum(Decimal32 x, Decimal32 y) => Number.SameQuantumDecimalIeee754<Decimal32, uint>(x._value, y._value);

/// <summary>Computes the absolute of a value.</summary>
/// <param name="value">The value for which to get its absolute.</param>
/// <returns>The absolute of <paramref name="value" />.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,48 @@ bool IFloatingPoint<Decimal64>.TryWriteSignificandLittleEndian(Span<byte> destin
return false;
}

//
// IFloatingPointIeee754
//

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.BitDecrement(TSelf)" />
public static Decimal64 BitDecrement(Decimal64 x) => new Decimal64(Number.BitDecrementDecimalIeee754<Decimal64, ulong>(x._value));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.BitIncrement(TSelf)" />
public static Decimal64 BitIncrement(Decimal64 x) => new Decimal64(Number.BitIncrementDecimalIeee754<Decimal64, ulong>(x._value));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.FusedMultiplyAdd(TSelf, TSelf, TSelf)" />
public static Decimal64 FusedMultiplyAdd(Decimal64 left, Decimal64 right, Decimal64 addend) => new Decimal64(Number.FusedMultiplyAddDecimalIeee754<Decimal64, ulong>(left._value, right._value, addend._value));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.Ieee754Remainder(TSelf, TSelf)" />
public static Decimal64 Ieee754Remainder(Decimal64 left, Decimal64 right) => new Decimal64(Number.Ieee754RemainderDecimalIeee754<Decimal64, ulong>(left._value, right._value));

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.ILogB(TSelf)" />
public static int ILogB(Decimal64 x) => Number.ILogBDecimalIeee754<Decimal64, ulong>(x._value);

/// <inheritdoc cref="IFloatingPointIeee754{TSelf}.ScaleB(TSelf, int)" />
public static Decimal64 ScaleB(Decimal64 x, int n) => new Decimal64(Number.ScaleBDecimalIeee754<Decimal64, ulong>(x._value, n));

/// <inheritdoc cref="IRootFunctions{TSelf}.Sqrt(TSelf)" />
public static Decimal64 Sqrt(Decimal64 x) => new Decimal64(Number.SqrtDecimalIeee754<Decimal64, ulong>(x._value));

/// <summary>Adjusts a value to the quantum (exponent) of another value, rounding to nearest with ties to even.</summary>
/// <param name="x">The value whose quantum is adjusted.</param>
/// <param name="y">The value that provides the target quantum.</param>
/// <returns><paramref name="x" /> expressed with the quantum of <paramref name="y" />, or NaN when the value cannot be represented at that quantum.</returns>
public static Decimal64 Quantize(Decimal64 x, Decimal64 y) => new Decimal64(Number.QuantizeDecimalIeee754<Decimal64, ulong>(x._value, y._value));

/// <summary>Computes the quantum of a value: one unit in the last place sharing its exponent.</summary>
/// <param name="x">The value whose quantum is returned.</param>
/// <returns>The quantum of <paramref name="x" />.</returns>
public static Decimal64 Quantum(Decimal64 x) => new Decimal64(Number.QuantumDecimalIeee754<Decimal64, ulong>(x._value));

/// <summary>Determines whether two values have the same quantum (exponent).</summary>
/// <param name="x">The first value to compare.</param>
/// <param name="y">The second value to compare.</param>
/// <returns><c>true</c> if <paramref name="x" /> and <paramref name="y" /> have the same quantum; otherwise, <c>false</c>.</returns>
public static bool SameQuantum(Decimal64 x, Decimal64 y) => Number.SameQuantumDecimalIeee754<Decimal64, ulong>(x._value, y._value);

/// <summary>Computes the absolute of a value.</summary>
/// <param name="value">The value for which to get its absolute.</param>
/// <returns>The absolute of <paramref name="value" />.</returns>
Expand Down
Loading
Loading