Skip to content

OnixLabs.Numerics.Float128

Matthew Layton edited this page Nov 15, 2026 · 3 revisions

Float128 Struct

Represents an IEEE 754 binary128 quadruple-precision floating-point number with a 113-bit significand, a 15-bit biased exponent, and a full generic-math surface that integrates seamlessly with .NET's numeric type system.

Namespace OnixLabs.Numerics
Assembly OnixLabs.Numerics.dll (NuGet)
Inheritance object → ValueType → Float128
Implements IBinaryFloatingPointIeee754<Float128>, IMinMaxValue<Float128>, IValueEquatable<Float128>, IValueComparable<Float128>, IConvertible

Definition

public readonly partial struct Float128 :
    IBinaryFloatingPointIeee754<Float128>,
    IMinMaxValue<Float128>,
    IValueEquatable<Float128>,
    IValueComparable<Float128>,
    IConvertible

Remarks

Float128 implements the IEEE 754-2008 binary128 format (also called quadruple precision). The 128-bit bit pattern is laid out as one sign bit, a 15-bit biased exponent (bias 16383), and a 112-bit trailing significand. For normal values an implicit leading one gives 113 significant bits of precision, which corresponds to approximately 33–36 significant decimal digits and supports finite values up to roughly ±1.19 × 10⁴⁹³². The smallest positive subnormal is approximately 3.36 × 10⁻⁴⁹⁵¹.

NaN and infinity — Float128 models all IEEE 754 special values: positive and negative infinity, positive and negative zero, and quiet NaN. The static predicates IsNaN, IsInfinity, IsZero, IsFinite, IsNormal, and IsSubnormal test these states. Comparison operators return false whenever either operand is NaN, matching IEEE 754 ordering semantics. Equals(Float128) and GetHashCode() use collection-friendly semantics: any two NaN bit patterns are considered equal, and positive and negative zero are considered equal.

Arithmetic — all four basic operations (+, -, *, /) and the modulus operator (%) are implemented with full IEEE 754 round-to-nearest-ties-to-even semantics, operating natively in 128-bit arithmetic. FusedMultiplyAdd is a true single-rounded FMA computed in a 512-bit accumulator.

Generic-math support — because Float128 implements IBinaryFloatingPointIeee754<Float128> it participates fully in .NET's generic-math infrastructure. Any algorithm constrained to IFloatingPoint<T>, INumber<T>, or INumberBase<T> accepts Float128 without modification. Explicitly-implemented interface members (INumberBase<Float128>.IsCanonical, INumberBase<Float128>.IsComplexNumber, etc.) are accessible via the interface and are not listed in the member tables.

Transcendental functions — Float128 provides a comprehensive set of transcendental functions directly: exponential (Exp, Exp2, Exp10, ExpM1, Exp2M1, Exp10M1), logarithmic (Log, Log2, Log10, LogP1, Log2P1, Log10P1, Log(value, base)), power/root (Pow, Sqrt, Cbrt, RootN, Hypot), trigonometric (Sin, Cos, Tan, SinCos, SinPi, CosPi, TanPi, SinCosPi), inverse trigonometric (Asin, Acos, Atan, Atan2, AsinPi, AcosPi, AtanPi, Atan2Pi), and hyperbolic / inverse hyperbolic (Sinh, Cosh, Tanh, Asinh, Acosh, Atanh). All functions are evaluated using range-reduced Taylor series.

Conversions — implicit widening conversions are provided from all built-in signed and unsigned integer types (sbyte, byte, short, ushort, int, uint, long, ulong, Int128, UInt128, char), as well as from the narrower floating-point types (Half, float, double) and from decimal. Narrowing explicit conversions to integer types truncate toward zero, saturating on overflow (unchecked form) or throwing OverflowException (checked form). Conversions to and from BigDecimal and BigInteger are also provided. Every source value is converted exactly when precision permits; wider integer types are rounded to nearest.

Formatting and parsing — ToString supports standard numeric format strings (G/R for round-trip, plus precision-bearing specifiers such as N, F, C, P) and reads NaN, infinity, and sign symbols from the NumberFormatInfo of the supplied provider. Parse and TryParse accept both string and ReadOnlySpan<char>, with optional NumberStyles control; scientific-notation exponents (E/e) are also recognised. The round-trip digit count for binary128 is 36.

Serialisation — the floating-point exponent and significand can be written to byte spans individually in either endianness via TryWriteExponentBigEndian, TryWriteExponentLittleEndian, TryWriteSignificandBigEndian, and TryWriteSignificandLittleEndian.

Relationship to siblings — Float128 and Float256 share a symmetric public API. Float256 offers double the bit width (237-bit significand) and is used internally by Float128.ToString as a high-precision intermediate during the binary-to-decimal conversion.

Examples

Construction and arithmetic

using OnixLabs.Numerics;

Float128 a = Float128.Parse("1.23456789012345678901234567890123456789");
Float128 b = (Float128)3.14159265358979323846264338327950288;  // implicit from double

Float128 sum  = a + b;
Float128 prod = a * b;
Float128 quot = a / b;

Console.WriteLine(Float128.IsFinite(sum));       // True
Console.WriteLine(Float128.IsNaN(Float128.NaN)); // True
Console.WriteLine(Float128.MaxValue);            // ~1.189731495357231765085759326628E+4932
Console.WriteLine(Float128.Epsilon);             // smallest positive subnormal

Transcendental functions and formatting

using OnixLabs.Numerics;
using System.Globalization;

Float128 angle = Float128.Pi / (Float128)4;
Float128 sinVal = Float128.Sin(angle);     // ~0.70710678118654752440...
Float128 logVal = Float128.Log(Float128.E); // 1 (exactly)
Float128 sqrtTwo = Float128.Sqrt((Float128)2);

// Round-trip: 36 significant decimal digits
string rt = sqrtTwo.ToString("G", CultureInfo.InvariantCulture);
Float128 parsed = Float128.Parse(rt, CultureInfo.InvariantCulture);
Console.WriteLine(parsed == sqrtTwo); // True

// Precision-bearing format
Console.WriteLine(sinVal.ToString("N10", CultureInfo.InvariantCulture));
// 0.7071067812

// Serialise the exponent and significand
Span<byte> expBuf = stackalloc byte[2];
sqrtTwo.TryWriteExponentBigEndian(expBuf, out _);

Span<byte> sigBuf = stackalloc byte[16];
sqrtTwo.TryWriteSignificandBigEndian(sigBuf, out _);

Fields and Static Properties

Member Type Description
Zero Float128 Positive zero (+0).
NegativeZero Float128 Negative zero (−0).
One Float128 The value one.
NegativeOne Float128 The value negative one.
Two Float128 The value two.
Ten Float128 The value ten.
Epsilon Float128 The smallest positive subnormal (least positive value).
MaxValue Float128 The largest finite positive value.
MinValue Float128 The smallest finite negative value (most negative).
PositiveInfinity Float128 Positive infinity.
NegativeInfinity Float128 Negative infinity.
NaN Float128 The canonical quiet not-a-number value.
AllBitsSet Float128 All 128 bits set (a negative NaN).
E Float128 Euler's number, rounded to binary128 precision.
Pi Float128 The ratio π of a circle's circumference to its diameter, rounded to binary128 precision.
Tau Float128 The number of radians in one turn (2π), rounded to binary128 precision.

Zero

public static Float128 Zero { get; }

Gets the Float128 value representing positive zero. This is the default value of the struct.

NegativeZero

public static Float128 NegativeZero { get; }

Gets the Float128 value representing negative zero. Negative zero compares equal to positive zero under IEEE 754 ordering semantics.

One

public static Float128 One { get; }

Gets the Float128 value representing positive one.

NegativeOne

public static Float128 NegativeOne { get; }

Gets the Float128 value representing negative one.

Two

public static Float128 Two { get; }

Gets the Float128 value representing the integer two.

Ten

public static Float128 Ten { get; }

Gets the Float128 value representing the integer ten.

Epsilon

public static Float128 Epsilon { get; }

Gets the smallest positive finite Float128 value that is greater than zero. This is a subnormal value with only the least-significant bit of the trailing significand set; its bit pattern is UInt128.One. Approximately 3.36 × 10⁻⁴⁹⁵¹.

MaxValue

public static Float128 MaxValue { get; }

Gets the largest finite positive Float128 value. Approximately 1.19 × 10⁴⁹³².

MinValue

public static Float128 MinValue { get; }

Gets the smallest finite negative Float128 value (the most negative finite number). Equal to −MaxValue.

PositiveInfinity

public static Float128 PositiveInfinity { get; }

Gets the Float128 value representing positive infinity.

NegativeInfinity

public static Float128 NegativeInfinity { get; }

Gets the Float128 value representing negative infinity.

NaN

public static Float128 NaN { get; }

Gets the canonical quiet not-a-number (NaN) Float128 value. All arithmetic operations that receive a NaN operand propagate NaN as the result.

AllBitsSet

public static Float128 AllBitsSet { get; }

Gets the Float128 value whose entire 128-bit pattern is ones. The bit pattern equals UInt128.MaxValue; this encodes a negative NaN.

E

public static Float128 E { get; }

Gets the natural logarithmic base (Euler's number, e ≈ 2.71828…), parsed from a 40-significant-digit decimal literal to guarantee a bit-correct binary128 result.

Pi

public static Float128 Pi { get; }

Gets the ratio of the circumference of a circle to its diameter (π ≈ 3.14159…), parsed from a 40-significant-digit decimal literal to guarantee a bit-correct binary128 result.

Tau

public static Float128 Tau { get; }

Gets the number of radians in one full turn (τ = 2π ≈ 6.28318…), parsed from a 40-significant-digit decimal literal to guarantee a bit-correct binary128 result.

Constructors

Constructor Description
Float128(UInt128) Initializes a new instance from the specified raw IEEE 754 binary128 bit pattern.

Float128(UInt128)

public Float128(UInt128 bits)

Initializes a new instance of the Float128 struct from the specified raw IEEE 754 binary128 bit pattern.

Parameter Type Description
bits UInt128 The raw 128-bit IEEE 754 binary128 bit pattern.

Properties

Property Type Description
Bits UInt128 Gets the raw IEEE 754 binary128 bit pattern of the current value.

Bits

public UInt128 Bits { get; }

Gets the raw 128-bit IEEE 754 binary128 representation of the current Float128 value. This property provides direct access to the bit pattern for low-level manipulation, serialisation, or construction of derived values.

Methods

Static Methods

Arithmetic

Method Returns Description
Abs(Float128) Float128 Returns the absolute value, preserving NaN payloads.
Negate(Float128) Float128 Returns the unary negation of the value.
Sign(Float128) int Returns −1, 0, or 1 indicating the sign.
Add(Float128, Float128) Float128 Computes the IEEE 754 round-to-nearest sum.
Subtract(Float128, Float128) Float128 Computes the IEEE 754 round-to-nearest difference.
Multiply(Float128, Float128) Float128 Computes the IEEE 754 round-to-nearest product.
Divide(Float128, Float128) Float128 Computes the IEEE 754 round-to-nearest quotient.
Modulus(Float128, Float128) Float128 Computes the truncating remainder.
FusedMultiplyAdd(Float128, Float128, Float128) Float128 Computes (left × right) + addend with a single final rounding.
Ieee754Remainder(Float128, Float128) Float128 Computes the IEEE 754 remainder using round-to-nearest-even on the quotient.
CopySign(Float128, Float128) Float128 Returns a value with the magnitude of magnitude and the sign of sign.

Rounding and truncation

Method Returns Description
Ceiling(Float128) Float128 Rounds toward positive infinity.
Floor(Float128) Float128 Rounds toward negative infinity.
Truncate(Float128) Float128 Rounds toward zero.
Round(Float128) Float128 Rounds to the nearest integer; ties to even.
Round(Float128, int) Float128 Rounds to a specified number of digits; ties to even.
Round(Float128, MidpointRounding) Float128 Rounds to the nearest integer using the specified midpoint strategy.
Round(Float128, int, MidpointRounding) Float128 Rounds to a specified number of digits using the specified midpoint strategy.

Comparison and clamping

Method Returns Description
Compare(Float128, Float128) int Imposes a total order; NaN sorts before all numeric values.
Min(Float128, Float128) Float128 Returns the smaller of two values; propagates NaN.
Max(Float128, Float128) Float128 Returns the larger of two values; propagates NaN.
MinNumber(Float128, Float128) Float128 Returns the smaller value; treats NaN as missing.
MaxNumber(Float128, Float128) Float128 Returns the larger value; treats NaN as missing.
MinMagnitude(Float128, Float128) Float128 Returns the value with the smaller absolute magnitude; propagates NaN.
MaxMagnitude(Float128, Float128) Float128 Returns the value with the larger absolute magnitude; propagates NaN.
MinMagnitudeNumber(Float128, Float128) Float128 Returns the value with the smaller absolute magnitude; treats NaN as missing.
MaxMagnitudeNumber(Float128, Float128) Float128 Returns the value with the larger absolute magnitude; treats NaN as missing.

Scaling and bit-manipulation

Method Returns Description
ILogB(Float128) int Returns the unbiased binary exponent; int.MaxValue for NaN/infinity; int.MinValue for zero.
ScaleB(Float128, int) Float128 Returns value × 2^n, saturating to infinity on overflow and to zero on underflow.
BitIncrement(Float128) Float128 Returns the next representable value above the argument.
BitDecrement(Float128) Float128 Returns the next representable value below the argument.
ReciprocalEstimate(Float128) Float128 Returns the correctly-rounded quotient 1 / value.
ReciprocalSqrtEstimate(Float128) Float128 Returns an approximation of 1 / √value, faithful to within 1 ULP.

Predicates

Method Returns Description
IsNaN(Float128) bool Returns true when the value is NaN.
IsInfinity(Float128) bool Returns true when the value is positive or negative infinity.
IsPositiveInfinity(Float128) bool Returns true when the value is positive infinity.
IsNegativeInfinity(Float128) bool Returns true when the value is negative infinity.
IsFinite(Float128) bool Returns true when the value is finite (not NaN, not infinity).
IsNormal(Float128) bool Returns true when the value is a normal (non-zero, non-subnormal, non-infinite, non-NaN) value.
IsSubnormal(Float128) bool Returns true when the value is a non-zero subnormal.
IsZero(Float128) bool Returns true when the value is positive or negative zero.
IsNegative(Float128) bool Returns true when the sign bit is set (including negative zero and negative NaN).
IsPositive(Float128) bool Returns true when the sign bit is clear (including positive zero and canonical NaN).
IsInteger(Float128) bool Returns true when the value is a finite integer.
IsEvenInteger(Float128) bool Returns true when the value is an even finite integer.
IsOddInteger(Float128) bool Returns true when the value is an odd finite integer.
IsPow2(Float128) bool Returns true when the value is a positive power of two.

Exponential functions

Method Returns Description
Exp(Float128) Float128 Computes e^value.
Exp2(Float128) Float128 Computes 2^value.
Exp10(Float128) Float128 Computes 10^value.
ExpM1(Float128) Float128 Computes e^value − 1, accurate near zero.
Exp2M1(Float128) Float128 Computes 2^value − 1, accurate near zero.
Exp10M1(Float128) Float128 Computes 10^value − 1, accurate near zero.

Logarithmic functions

Method Returns Description
Log(Float128) Float128 Computes the natural logarithm.
Log2(Float128) Float128 Computes the base-2 logarithm.
Log10(Float128) Float128 Computes the base-10 logarithm.
Log(Float128, Float128) Float128 Computes the logarithm in a specified base.
LogP1(Float128) Float128 Computes ln(1 + value), accurate near zero.
Log2P1(Float128) Float128 Computes log2(1 + value), accurate near zero.
Log10P1(Float128) Float128 Computes log10(1 + value), accurate near zero.

Power and root functions

Method Returns Description
Pow(Float128, Float128) Float128 Computes x^y following IEEE 754-2019 special-case rules.
Sqrt(Float128) Float128 Computes the square root; faithful to within 1 ULP.
Cbrt(Float128) Float128 Computes the cube root; preserves the sign of negative inputs.
RootN(Float128, int) Float128 Computes the _n_th root.
Hypot(Float128, Float128) Float128 Computes √(x² + y²), avoiding intermediate overflow.

Trigonometric functions

Method Returns Description
Sin(Float128) Float128 Computes the sine of an angle in radians.
Cos(Float128) Float128 Computes the cosine of an angle in radians.
Tan(Float128) Float128 Computes the tangent of an angle in radians.
SinCos(Float128) (Float128 Sin, Float128 Cos) Computes sine and cosine simultaneously.
SinPi(Float128) Float128 Computes sin(π · value).
CosPi(Float128) Float128 Computes cos(π · value).
TanPi(Float128) Float128 Computes tan(π · value).
SinCosPi(Float128) (Float128 SinPi, Float128 CosPi) Computes sin(π · value) and cos(π · value) simultaneously.

Inverse trigonometric functions

Method Returns Description
Asin(Float128) Float128 Computes the arcsine; input in [−1, 1]; result in radians.
Acos(Float128) Float128 Computes the arccosine; input in [−1, 1]; result in radians.
Atan(Float128) Float128 Computes the arctangent; result in radians.
Atan2(Float128, Float128) Float128 Computes atan(y/x) accounting for quadrant; result in radians.
AsinPi(Float128) Float128 Computes Asin(value) / π.
AcosPi(Float128) Float128 Computes Acos(value) / π.
AtanPi(Float128) Float128 Computes Atan(value) / π.
Atan2Pi(Float128, Float128) Float128 Computes Atan2(y, x) / π.

Hyperbolic functions

Method Returns Description
Sinh(Float128) Float128 Computes the hyperbolic sine.
Cosh(Float128) Float128 Computes the hyperbolic cosine.
Tanh(Float128) Float128 Computes the hyperbolic tangent.
Asinh(Float128) Float128 Computes the inverse hyperbolic sine.
Acosh(Float128) Float128 Computes the inverse hyperbolic cosine; domain [1, +∞).
Atanh(Float128) Float128 Computes the inverse hyperbolic tangent; domain [−1, 1].

Parsing

Method Returns Description
Parse(string, IFormatProvider?) Float128 Parses a string.
Parse(string, NumberStyles, IFormatProvider?) Float128 Parses a string with explicit number styles.
Parse(ReadOnlySpan&lt;char&gt;, IFormatProvider?) Float128 Parses a character span.
Parse(ReadOnlySpan&lt;char&gt;, NumberStyles, IFormatProvider?) Float128 Parses a character span with explicit number styles.
TryParse(string?, out Float128) bool Attempts to parse a string; returns false on failure.
TryParse(string?, IFormatProvider?, out Float128) bool Attempts to parse a string with a format provider.
TryParse(string?, NumberStyles, IFormatProvider?, out Float128) bool Attempts to parse a string with number styles and a format provider.
TryParse(ReadOnlySpan&lt;char&gt;, out Float128) bool Attempts to parse a character span; returns false on failure.
TryParse(ReadOnlySpan&lt;char&gt;, IFormatProvider?, out Float128) bool Attempts to parse a character span with a format provider.
TryParse(ReadOnlySpan&lt;char&gt;, NumberStyles, IFormatProvider?, out Float128) bool Attempts to parse a character span with number styles and a format provider.

Equality

Method Returns Description
Equals(Float128, Float128) bool Determines whether two Float128 values are equal under collection-equality semantics.

Abs(Float128)

public static Float128 Abs(Float128 value)

Returns the absolute value of value by clearing the sign bit. NaN payloads are preserved: any NaN input produces a NaN result. Negative zero becomes positive zero; negative infinity becomes positive infinity.

Parameter Type Description
value Float128 The value whose absolute value is to be computed.

Returns — The absolute value of value.

Negate(Float128)

public static Float128 Negate(Float128 value)

Returns the unary negation of value. Equivalent to applying the − unary operator.

Parameter Type Description
value Float128 The value to negate.

Returns — The negation of value.

Sign(Float128)

public static int Sign(Float128 value)

Returns an integer indicating the sign of the specified value.

Parameter Type Description
value Float128 The value whose sign is to be returned.

Returns — −1 if value is negative; 0 if value is zero; 1 if value is positive.

Exceptions

Exception Condition
ArithmeticException value is NaN.

Add(Float128, Float128)

public static Float128 Add(Float128 left, Float128 right)

Computes the sum of two Float128 values, rounded to nearest, ties-to-even per IEEE 754.

Parameter Type Description
left Float128 The left addend.
right Float128 The right addend.

Returns — The correctly-rounded sum.

Subtract(Float128, Float128)

public static Float128 Subtract(Float128 left, Float128 right)

Computes the difference of two Float128 values, rounded to nearest, ties-to-even per IEEE 754.

Parameter Type Description
left Float128 The minuend.
right Float128 The subtrahend.

Returns — The correctly-rounded difference.

Multiply(Float128, Float128)

public static Float128 Multiply(Float128 left, Float128 right)

Computes the product of two Float128 values, rounded to nearest, ties-to-even per IEEE 754. The full 256-bit product of the two 113-bit significands is computed before rounding.

Parameter Type Description
left Float128 The left multiplicand.
right Float128 The right multiplicand.

Returns — The correctly-rounded product.

Divide(Float128, Float128)

public static Float128 Divide(Float128 left, Float128 right)

Computes the quotient of two Float128 values, rounded to nearest, ties-to-even per IEEE 754.

Parameter Type Description
left Float128 The dividend.
right Float128 The divisor.

Returns — The correctly-rounded quotient; NaN if both are zero or if left is infinity and right is infinity; PositiveInfinity or NegativeInfinity if right is zero.

Modulus(Float128, Float128)

public static Float128 Modulus(Float128 left, Float128 right)

Computes the truncating remainder of dividing left by right (C# % semantics, not the IEEE 754 remainder). The result has the same sign as the dividend.

Parameter Type Description
left Float128 The dividend.
right Float128 The divisor.

Returns — The truncating remainder.

FusedMultiplyAdd(Float128, Float128, Float128)

public static Float128 FusedMultiplyAdd(Float128 left, Float128 right, Float128 addend)

Computes (left × right) + addend with a single final rounding, eliminating intermediate rounding error. The product is computed exactly in a 256-bit intermediate and accumulated in a 512-bit buffer before the single round-to-nearest-ties-to-even step.

Parameter Type Description
left Float128 The first multiplicand.
right Float128 The second multiplicand.
addend Float128 The value to add to the product.

Returns — (left × right) + addend with a single final rounding; NaN when any operand is NaN or for the indeterminate form 0 × ∞.

Ieee754Remainder(Float128, Float128)

public static Float128 Ieee754Remainder(Float128 left, Float128 right)

Computes the IEEE 754 remainder of left divided by right. The remainder is defined as left − n × right, where n is left / right rounded to the nearest integer with ties to even. Every arithmetic step is exact.

Parameter Type Description
left Float128 The dividend.
right Float128 The divisor.

Returns — The IEEE 754 remainder; NaN for invalid combinations (infinity dividend, zero divisor, or any NaN operand).

CopySign(Float128, Float128)

public static Float128 CopySign(Float128 magnitude, Float128 sign)

Returns a Float128 value with the magnitude of magnitude and the sign bit of sign.

Parameter Type Description
magnitude Float128 The value whose magnitude is used.
sign Float128 The value whose sign bit is used.

Returns — A value combining the magnitude of magnitude with the sign of sign.

Ceiling(Float128)

public static Float128 Ceiling(Float128 value)

Computes the smallest integral Float128 value that is greater than or equal to value (rounds toward positive infinity). NaN, ±infinity, and ±zero are returned unchanged.

Returns — The ceiling of value.

Floor(Float128)

public static Float128 Floor(Float128 value)

Computes the largest integral Float128 value that is less than or equal to value (rounds toward negative infinity). NaN, ±infinity, and ±zero are returned unchanged.

Returns — The floor of value.

Truncate(Float128)

public static Float128 Truncate(Float128 value)

Computes the integral component of value by rounding toward zero. Fractional bits in the significand are masked out. NaN, ±infinity, and ±zero are returned unchanged.

Returns — The integral component of value.

Round(Float128)

public static Float128 Round(Float128 value)

Rounds value to the nearest integer using round-half-to-even (banker's rounding) for ties. NaN, ±infinity, and ±zero are returned unchanged.

Returns — The nearest integer value.

Round(Float128, int)

public static Float128 Round(Float128 value, int digits)

Rounds value to digits fractional digits using round-half-to-even for ties. A negative digits argument rounds to a corresponding power of ten in the integer part.

Parameter Type Description
value Float128 The value to round.
digits int The number of fractional digits.

Returns — The rounded value.

Round(Float128, MidpointRounding)

public static Float128 Round(Float128 value, MidpointRounding mode)

Rounds value to the nearest integer using the specified midpoint-rounding strategy.

Parameter Type Description
value Float128 The value to round.
mode MidpointRounding The rounding strategy for values exactly halfway between two integers.

Returns — The rounded value.

Exceptions

Exception Condition
ArgumentOutOfRangeException mode is not a defined MidpointRounding value.

Round(Float128, int, MidpointRounding)

public static Float128 Round(Float128 value, int digits, MidpointRounding mode)

Rounds value to digits fractional digits using the specified midpoint-rounding strategy.

Parameter Type Description
value Float128 The value to round.
digits int The number of fractional digits.
mode MidpointRounding The rounding strategy.

Returns — The rounded value.

Exceptions

Exception Condition
ArgumentOutOfRangeException mode is not a defined MidpointRounding value.

Compare(Float128, Float128)

public static int Compare(Float128 left, Float128 right)

Compares two Float128 values and returns a signed ordering indicator. Imposes a total order: any NaN sorts before all numeric values; negative infinity is the smallest numeric value; positive zero and negative zero compare equal.

Parameter Type Description
left Float128 The left value.
right Float128 The right value.

Returns — A negative integer if left precedes right; zero if they are equal; a positive integer if left follows right.

Min(Float128, Float128)

public static Float128 Min(Float128 x, Float128 y)

Returns the smaller of two values. Returns NaN if either operand is NaN. When values are equal, the negative value (including negative zero) is preferred.

Returns — The lesser of x and y; NaN if either is NaN.

Max(Float128, Float128)

public static Float128 Max(Float128 x, Float128 y)

Returns the larger of two values. Returns NaN if either operand is NaN. When values are equal, the positive value is preferred.

Returns — The greater of x and y; NaN if either is NaN.

MinNumber(Float128, Float128)

public static Float128 MinNumber(Float128 x, Float128 y)

Returns the smaller of two values, treating NaN as missing. If exactly one operand is NaN, returns the non-NaN operand; if both are NaN, returns NaN.

MaxNumber(Float128, Float128)

public static Float128 MaxNumber(Float128 x, Float128 y)

Returns the larger of two values, treating NaN as missing.

MinMagnitude(Float128, Float128)

public static Float128 MinMagnitude(Float128 x, Float128 y)

Returns the value with the smaller absolute magnitude; propagates NaN. When magnitudes are equal, the negative value is preferred.

MaxMagnitude(Float128, Float128)

public static Float128 MaxMagnitude(Float128 x, Float128 y)

Returns the value with the larger absolute magnitude; propagates NaN. When magnitudes are equal, the positive value is preferred.

MinMagnitudeNumber(Float128, Float128)

public static Float128 MinMagnitudeNumber(Float128 x, Float128 y)

Returns the value with the smaller absolute magnitude; treats NaN as missing.

MaxMagnitudeNumber(Float128, Float128)

public static Float128 MaxMagnitudeNumber(Float128 x, Float128 y)

Returns the value with the larger absolute magnitude; treats NaN as missing.

ILogB(Float128)

public static int ILogB(Float128 value)

Returns the integral base-2 logarithm (unbiased binary exponent) of value.

Parameter Type Description
value Float128 The value to inspect.

Returns — The unbiased exponent; int.MaxValue for NaN or infinity; int.MinValue for zero.

ScaleB(Float128, int)

public static Float128 ScaleB(Float128 value, int n)

Returns value × 2^n. NaN, infinity, and zero are returned unchanged. Overflows saturate to the appropriately-signed infinity; underflows taper to subnormal or signed zero.

Parameter Type Description
value Float128 The value to scale.
n int The integer power of two.

Returns — value × 2^n.

BitIncrement(Float128)

public static Float128 BitIncrement(Float128 value)

Returns the smallest Float128 value that is greater than value. NaN remains NaN; positive infinity remains positive infinity; negative infinity becomes MinValue; either zero becomes Epsilon.

BitDecrement(Float128)

public static Float128 BitDecrement(Float128 value)

Returns the largest Float128 value that is less than value. NaN remains NaN; negative infinity remains negative infinity; positive infinity becomes MaxValue; either zero becomes the largest negative subnormal.

ReciprocalEstimate

public static Float128 ReciprocalEstimate(Float128 value)

Returns the correctly-rounded quotient 1 / value.

ReciprocalSqrtEstimate

public static Float128 ReciprocalSqrtEstimate(Float128 value)

Returns an approximation of 1 / √value, faithful to within 1 ULP (inheriting the accuracy of Sqrt).

IsNaN(Float128)

public static bool IsNaN(Float128 value)

Returns true when value is a not-a-number (NaN) value.

IsInfinity

public static bool IsInfinity(Float128 value)

Returns true when value is positive or negative infinity.

IsPositiveInfinity

public static bool IsPositiveInfinity(Float128 value)

Returns true when value is positive infinity.

IsNegativeInfinity

public static bool IsNegativeInfinity(Float128 value)

Returns true when value is negative infinity.

IsFinite

public static bool IsFinite(Float128 value)

Returns true when value is finite (not NaN and not infinity).

IsNormal

public static bool IsNormal(Float128 value)

Returns true when value is a normal value — finite, non-zero, and not subnormal.

IsSubnormal

public static bool IsSubnormal(Float128 value)

Returns true when value is a non-zero subnormal value (biased exponent field equals zero and trailing significand is non-zero).

IsZero

public static bool IsZero(Float128 value)

Returns true when value is positive zero or negative zero.

IsNegative

public static bool IsNegative(Float128 value)

Returns true when the sign bit of value is set. This includes negative zero and negative NaN bit patterns.

IsPositive

public static bool IsPositive(Float128 value)

Returns true when the sign bit of value is clear. This includes positive zero and the canonical NaN bit pattern.

IsInteger

public static bool IsInteger(Float128 value)

Returns true when value is a finite number with no fractional component (an exact integer). Returns false for NaN, infinity, and values whose magnitude is less than 1 with non-zero fractional bits.

IsEvenInteger

public static bool IsEvenInteger(Float128 value)

Returns true when value is a finite even integer.

IsOddInteger

public static bool IsOddInteger(Float128 value)

Returns true when value is a finite odd integer.

IsPow2

public static bool IsPow2(Float128 value)

Returns true when value is a positive integer that is an exact power of two.

Exp(Float128)

public static Float128 Exp(Float128 value)

Computes e^value. Returns NaN for NaN; PositiveInfinity for positive infinity or overflow; Zero for negative infinity or underflow.

Exp2(Float128)

public static Float128 Exp2(Float128 value)

Computes 2^value. For integer arguments that fit in the binary128 exponent range, the result is exact via ScaleB. Returns NaN for NaN; PositiveInfinity on overflow; Zero on underflow.

Exp10(Float128)

public static Float128 Exp10(Float128 value)

Computes 10^value via Exp(value × ln 10). Returns NaN for NaN; PositiveInfinity on overflow; Zero on underflow.

ExpM1(Float128)

public static Float128 ExpM1(Float128 value)

Computes e^value − 1, using the direct Taylor series for small value to avoid catastrophic cancellation near zero. Returns NegativeOne for negative infinity; preserves the sign of zero.

Exp2M1(Float128)

public static Float128 Exp2M1(Float128 value)

Computes 2^value − 1, accurate near zero. Returns NegativeOne for negative infinity.

Exp10M1(Float128)

public static Float128 Exp10M1(Float128 value)

Computes 10^value − 1, accurate near zero. Returns NegativeOne for negative infinity.

Log(Float128)

public static Float128 Log(Float128 value)

Computes the natural logarithm of value. Returns NaN for negative inputs and NaN; NegativeInfinity for zero; PositiveInfinity for positive infinity.

Log2(Float128)

public static Float128 Log2(Float128 value)

Computes the base-2 logarithm of value. For exact powers of two, returns the unbiased exponent as a Float128 integer. Returns NaN for negative inputs and NaN; NegativeInfinity for zero.

Log10(Float128)

public static Float128 Log10(Float128 value)

Computes the base-10 logarithm of value. Returns NaN for negative inputs and NaN; NegativeInfinity for zero.

Log(Float128, Float128)

public static Float128 Log(Float128 value, Float128 newBase)

Computes the logarithm of value in base newBase. Dispatches to Log2 when newBase is two, and to Log10 when newBase is ten; otherwise computes Log(value) / Log(newBase). Returns NaN when newBase is one.

Parameter Type Description
value Float128 The value whose logarithm is to be computed.
newBase Float128 The logarithm base.

Returns — log_newBase_(value).

LogP1(Float128)

public static Float128 LogP1(Float128 value)

Computes ln(1 + value), using the atanh Taylor series directly for small |value| to retain precision near zero. Returns NaN for inputs less than −1; NegativeInfinity when value == −1; PositiveInfinity for positive infinity.

Log2P1(Float128)

public static Float128 Log2P1(Float128 value)

Computes log2(1 + value), accurate near zero.

Log10P1(Float128)

public static Float128 Log10P1(Float128 value)

Computes log10(1 + value), accurate near zero.

Pow(Float128, Float128)

public static Float128 Pow(Float128 x, Float128 y)

Computes x^y following IEEE 754-2019 special-case rules. For positive integer exponents up to 64, exact integer exponentiation by squaring is used; for all other cases the computation falls back to Exp(y × Log(x)).

Parameter Type Description
x Float128 The base.
y Float128 The exponent.

Returns — x^y.

Sqrt(Float128)

public static Float128 Sqrt(Float128 value)

Computes the square root of value, faithful to within 1 ULP using Newton-Raphson iteration seeded from an exponent-derived estimate that is valid across the full binary128 range. Returns NaN for negative inputs or NaN; preserves the sign of zero.

Parameter Type Description
value Float128 The radicand.

Returns — √value.

Cbrt(Float128)

public static Float128 Cbrt(Float128 value)

Computes the cube root of value using Newton-Raphson iteration. Preserves the sign of negative inputs and the sign of zero; ±infinity for ±infinity.

RootN(Float128, int)

public static Float128 RootN(Float128 value, int n)

Computes the _n_th root of value. Dispatches to Sqrt for n == 2, Cbrt for n == 3, and 1 / value for n == -1; otherwise computes Exp(Log(|value|) / n). Returns NaN for an even root of a negative value; NaN for n == 0.

Parameter Type Description
value Float128 The radicand.
n int The root index.

Returns — The _n_th root of value.

Hypot(Float128, Float128)

public static Float128 Hypot(Float128 x, Float128 y)

Computes √(x² + y²) (Euclidean length), avoiding intermediate overflow by dividing through by max(|x|, |y|) before squaring.

Parameter Type Description
x Float128 The first value.
y Float128 The second value.

Returns — √(x² + y²); PositiveInfinity if either argument is infinite.

Sin(Float128)

public static Float128 Sin(Float128 value)

Computes the sine of value (angle in radians). Returns NaN for NaN or infinity; preserves the sign of zero.

Cos(Float128)

public static Float128 Cos(Float128 value)

Computes the cosine of value (angle in radians). Returns NaN for NaN or infinity; returns One for zero.

Tan(Float128)

public static Float128 Tan(Float128 value)

Computes the tangent of value (angle in radians). Returns NaN for NaN or infinity; preserves the sign of zero.

SinCos(Float128)

public static (Float128 Sin, Float128 Cos) SinCos(Float128 value)

Computes the sine and cosine of value simultaneously, sharing the underlying range-reduction and series evaluations.

Parameter Type Description
value Float128 The angle, in radians.

Returns — A tuple (Sin, Cos).

SinPi(Float128)

public static Float128 SinPi(Float128 value)

Computes sin(π · value). Returns exact zero for integer arguments.

CosPi(Float128)

public static Float128 CosPi(Float128 value)

Computes cos(π · value). Returns One for zero.

TanPi(Float128)

public static Float128 TanPi(Float128 value)

Computes tan(π · value). Returns exact zero for integer arguments.

SinCosPi(Float128)

public static (Float128 SinPi, Float128 CosPi) SinCosPi(Float128 value)

Computes sin(π · value) and cos(π · value) simultaneously.

Returns — A tuple (SinPi, CosPi).

Asin(Float128)

public static Float128 Asin(Float128 value)

Computes the arcsine of value, returning the angle in radians. Domain: [−1, 1]. Returns NaN for NaN or values outside the domain; preserves the sign of zero.

Acos(Float128)

public static Float128 Acos(Float128 value)

Computes the arccosine of value, returning the angle in radians. Domain: [−1, 1]. Returns NaN for NaN or values outside the domain.

Atan(Float128)

public static Float128 Atan(Float128 value)

Computes the arctangent of value, returning the angle in radians in the range (−π/2, π/2). Preserves the sign of zero; returns ±π/2 for ±infinity.

Atan2(Float128, Float128)

public static Float128 Atan2(Float128 y, Float128 x)

Computes atan(y/x), resolving the quadrant of the result from the signs of both arguments. Returns the angle in radians in the range (−π, π].

Parameter Type Description
y Float128 The numerator (y-coordinate).
x Float128 The denominator (x-coordinate).

Returns — The angle in radians whose tangent is y/x.

AsinPi(Float128)

public static Float128 AsinPi(Float128 value)

Computes Asin(value) / π.

AcosPi(Float128)

public static Float128 AcosPi(Float128 value)

Computes Acos(value) / π.

AtanPi(Float128)

public static Float128 AtanPi(Float128 value)

Computes Atan(value) / π; returns ±½ for ±infinity.

Atan2Pi(Float128, Float128)

public static Float128 Atan2Pi(Float128 y, Float128 x)

Computes Atan2(y, x) / π, resolving all four quadrants.

Sinh(Float128)

public static Float128 Sinh(Float128 value)

Computes the hyperbolic sine of value. Preserves the sign of zero; returns ±infinity for ±infinity or on overflow.

Cosh(Float128)

public static Float128 Cosh(Float128 value)

Computes the hyperbolic cosine of value. Returns One for zero; PositiveInfinity for ±infinity or on overflow.

Tanh(Float128)

public static Float128 Tanh(Float128 value)

Computes the hyperbolic tangent of value. Saturates to ±1 for large magnitudes and for ±infinity; preserves the sign of zero.

Asinh(Float128)

public static Float128 Asinh(Float128 value)

Computes the inverse hyperbolic sine of value. Preserves the sign of zero; returns ±infinity for ±infinity.

Acosh(Float128)

public static Float128 Acosh(Float128 value)

Computes the inverse hyperbolic cosine of value. Domain: [1, +∞). Returns NaN for inputs less than one; Zero for one; PositiveInfinity for positive infinity.

Atanh(Float128)

public static Float128 Atanh(Float128 value)

Computes the inverse hyperbolic tangent of value. Domain: [−1, 1]. Preserves the sign of zero; returns ±infinity at ±1; NaN for inputs outside the domain.

Parse(string, IFormatProvider?)

public static Float128 Parse(string value, IFormatProvider? provider = null)

Parses a string representation of a Float128 value. Recognises the culture-specific NaN, positive-infinity, and negative-infinity symbols, decimal digits, an optional decimal point, and an optional E/e exponent marker.

Parameter Type Description
value string The string to parse.
provider IFormatProvider? An optional culture-specific format provider.

Returns — The parsed Float128 value.

Exceptions

Exception Condition
FormatException value is not in a valid format.

Parse(string, NumberStyles, IFormatProvider?)

public static Float128 Parse(string value, NumberStyles style, IFormatProvider? provider = null)

Parses a string representation using the specified NumberStyles.

Parameter Type Description
value string The string to parse.
style NumberStyles A bitwise combination of number-style flags governing which components are allowed.
provider IFormatProvider? An optional culture-specific format provider.

Returns — The parsed Float128 value.

Exceptions

Exception Condition
FormatException value is not in a valid format.

Parse(ReadOnlySpan<char>, IFormatProvider?)

public static Float128 Parse(ReadOnlySpan<char> value, IFormatProvider? provider = null)

Parses a character span. Avoids string allocation.

Parameter Type Description
value ReadOnlySpan<char> The character span to parse.
provider IFormatProvider? An optional culture-specific format provider.

Returns — The parsed Float128 value.

Exceptions

Exception Condition
FormatException The span is not in a valid format.

Parse(ReadOnlySpan<char>, NumberStyles, IFormatProvider?)

public static Float128 Parse(ReadOnlySpan<char> value, NumberStyles style, IFormatProvider? provider = null)

Parses a character span using the specified NumberStyles.

Parameter Type Description
value ReadOnlySpan<char> The character span to parse.
style NumberStyles A bitwise combination of number-style flags.
provider IFormatProvider? An optional culture-specific format provider.

Returns — The parsed Float128 value.

Exceptions

Exception Condition
FormatException The span is not in a valid format.

TryParse(string?, out Float128)

public static bool TryParse(string? value, out Float128 result)

Attempts to parse a string into a Float128 value. Returns false without throwing if parsing fails.

Parameter Type Description
value string? The string to parse.
result out Float128 The parsed value on success; otherwise, default.

Returns — true if parsing succeeded; otherwise, false.

TryParse(string?, IFormatProvider?, out Float128)

public static bool TryParse(string? value, IFormatProvider? provider, out Float128 result)

Attempts to parse a string with a format provider.

Parameter Type Description
value string? The string to parse.
provider IFormatProvider? An optional culture-specific format provider.
result out Float128 The parsed value on success; otherwise, default.

Returns — true if parsing succeeded; otherwise, false.

TryParse(string?, NumberStyles, IFormatProvider?, out Float128)

public static bool TryParse(string? value, NumberStyles style, IFormatProvider? provider, out Float128 result)

Attempts to parse a string with number styles and a format provider.

Parameter Type Description
value string? The string to parse.
style NumberStyles A bitwise combination of number-style flags.
provider IFormatProvider? An optional culture-specific format provider.
result out Float128 The parsed value on success; otherwise, default.

Returns — true if parsing succeeded; otherwise, false.

TryParse(ReadOnlySpan<char>, out Float128)

public static bool TryParse(ReadOnlySpan<char> value, out Float128 result)

Attempts to parse a character span using the current culture.

Parameter Type Description
value ReadOnlySpan<char> The character span to parse.
result out Float128 The parsed value on success; otherwise, default.

Returns — true if parsing succeeded; otherwise, false.

TryParse(ReadOnlySpan<char>, IFormatProvider?, out Float128)

public static bool TryParse(ReadOnlySpan<char> value, IFormatProvider? provider, out Float128 result)

Attempts to parse a character span with a format provider.

Parameter Type Description
value ReadOnlySpan<char> The character span to parse.
provider IFormatProvider? An optional culture-specific format provider.
result out Float128 The parsed value on success; otherwise, false.

Returns — true if parsing succeeded; otherwise, false.

TryParse(ReadOnlySpan<char>, NumberStyles, IFormatProvider?, out Float128)

public static bool TryParse(ReadOnlySpan<char> value, NumberStyles style, IFormatProvider? provider, out Float128 result)

Attempts to parse a character span with number styles and a format provider.

Parameter Type Description
value ReadOnlySpan<char> The character span to parse.
style NumberStyles A bitwise combination of number-style flags.
provider IFormatProvider? An optional culture-specific format provider.
result out Float128 The parsed value on success; otherwise, default.

Returns — true if parsing succeeded; otherwise, false.

Equals(Float128, Float128)

public static bool Equals(Float128 left, Float128 right)

Determines whether two Float128 values are equal using collection-equality semantics: any two NaN bit patterns are considered equal, and positive zero equals negative zero. This matches the contract of double.Equals(double).

Parameter Type Description
left Float128 The first value.
right Float128 The second value.

Returns — true if the values are equal under collection-equality semantics; otherwise, false.


Instance Methods

Method Returns Description
CompareTo(Float128) int Compares this instance with another Float128 using the total order defined by Compare.
CompareTo(object?) int Compares this instance with another object.
Equals(Float128) bool Determines whether this instance equals another Float128 under collection-equality semantics.
Equals(object?) bool Determines whether this instance equals another object.
GetHashCode() int Returns a hash code consistent with Equals.
GetExponentByteCount() int Returns the byte count needed to serialise the exponent (always 2).
GetExponentShortestBitLength() int Returns the shortest two's-complement bit length of the current exponent.
GetSignificandBitLength() int Returns the bit length of the significand including the implicit bit (always 113).
GetSignificandByteCount() int Returns the byte count needed to serialise the significand (always 16).
TryWriteExponentBigEndian(Span&lt;byte&gt;, out int) bool Writes the exponent to a big-endian byte span.
TryWriteExponentLittleEndian(Span&lt;byte&gt;, out int) bool Writes the exponent to a little-endian byte span.
TryWriteSignificandBigEndian(Span&lt;byte&gt;, out int) bool Writes the significand (with implicit bit) to a big-endian byte span.
TryWriteSignificandLittleEndian(Span&lt;byte&gt;, out int) bool Writes the significand (with implicit bit) to a little-endian byte span.
ToString() string Returns the default string representation (G format, current culture).
ToString(string?, IFormatProvider?) string Returns the string representation using the specified format and provider.

CompareTo(Float128)

public int CompareTo(Float128 other)

Compares this instance with another Float128 value using the total order defined by Compare: NaN sorts before all numeric values; positive and negative zero compare equal.

Parameter Type Description
other Float128 The value to compare with this instance.

Returns — A negative integer if this instance precedes other; zero if equal; a positive integer if this instance follows other.

CompareTo(object?)

public int CompareTo(object? obj)

Compares this instance with another object.

Parameter Type Description
obj object? The object to compare. A null reference sorts before any Float128.

Returns — A signed ordering indicator.

Exceptions

Exception Condition
ArgumentException obj is not null and is not a Float128.

Equals(Float128)

public bool Equals(Float128 other)

Determines whether this instance is equal to other under collection-equality semantics: NaN equals NaN; positive zero equals negative zero.

Returns — true if the values are equal; otherwise, false.

Equals(object?)

public override bool Equals(object? obj)

Determines whether this instance is equal to another object.

Returns — true if obj is a Float128 that is equal to this instance; otherwise, false.

GetHashCode()

public override int GetHashCode()

Returns a hash code consistent with Equals: all NaN bit patterns share the canonical NaN hash code; positive zero and negative zero share the positive-zero hash code.

Returns — A 32-bit signed integer hash code.

GetExponentByteCount()

public int GetExponentByteCount()

Returns the number of bytes required to serialise the current exponent via TryWriteExponentBigEndian or TryWriteExponentLittleEndian.

Returns — Always returns 2 (sizeof(short)).

GetExponentShortestBitLength()

public int GetExponentShortestBitLength()

Returns the length in bits of the shortest two's-complement representation of the current unbiased exponent.

Returns — The shortest bit length of the unbiased exponent.

GetSignificandBitLength()

public int GetSignificandBitLength()

Returns the bit length of the full significand, including the implicit leading bit for normal values.

Returns — Always returns 113.

GetSignificandByteCount()

public int GetSignificandByteCount()

Returns the number of bytes required to serialise the significand via TryWriteSignificandBigEndian or TryWriteSignificandLittleEndian.

Returns — Always returns 16.

TryWriteExponentBigEndian(Span<byte>, out int)

public bool TryWriteExponentBigEndian(Span<byte> destination, out int bytesWritten)

Tries to write the current unbiased exponent as a big-endian signed 16-bit integer to destination.

Parameter Type Description
destination Span<byte> The target span; must be at least 2 bytes.
bytesWritten out int 2 on success; 0 if destination is too short.

Returns — true if the exponent was written successfully; otherwise, false.

TryWriteExponentLittleEndian(Span<byte>, out int)

public bool TryWriteExponentLittleEndian(Span<byte> destination, out int bytesWritten)

Tries to write the current unbiased exponent as a little-endian signed 16-bit integer to destination.

Parameter Type Description
destination Span<byte> The target span; must be at least 2 bytes.
bytesWritten out int 2 on success; 0 if destination is too short.

Returns — true if the exponent was written successfully; otherwise, false.

TryWriteSignificandBigEndian(Span<byte>, out int)

public bool TryWriteSignificandBigEndian(Span<byte> destination, out int bytesWritten)

Tries to write the 113-bit significand (with the implicit leading bit set for normal values) as a big-endian 16-byte value to destination.

Parameter Type Description
destination Span<byte> The target span; must be at least 16 bytes.
bytesWritten out int 16 on success; 0 if destination is too short.

Returns — true if the significand was written successfully; otherwise, false.

TryWriteSignificandLittleEndian(Span<byte>, out int)

public bool TryWriteSignificandLittleEndian(Span<byte> destination, out int bytesWritten)

Tries to write the 113-bit significand as a little-endian 16-byte value to destination.

Parameter Type Description
destination Span<byte> The target span; must be at least 16 bytes.
bytesWritten out int 16 on success; 0 if destination is too short.

Returns — true if the significand was written successfully; otherwise, false.

ToString()

public override string ToString()

Returns the string representation of the current value using the G (general) format and the current culture. NaN, positive infinity, and negative infinity are rendered as the corresponding symbols from the current culture's NumberFormatInfo. The round-trip digit count for binary128 is 36.

Returns — A string representation of the current value.

ToString(string?, IFormatProvider?)

public string ToString(string? format, IFormatProvider? formatProvider = null)

Returns the string representation using the specified format and format provider. The G and R specifiers produce a round-trip representation with up to 36 significant digits, for values of any magnitude, including values of 10^36 or more whose integer part has more digits than the requested precision; precision-bearing specifiers (N, F, C, P, etc.) route through NumberInfo for correct padding and grouping. NaN and infinity symbols are always sourced from the NumberFormatInfo of the supplied provider.

Parameter Type Description
format string? A standard numeric format string, or null for the default G format.
formatProvider IFormatProvider? An optional culture-specific format provider.

Returns — The formatted string.

Operators

Arithmetic Operators

Operator Returns Description
operator +(Float128) Float128 Unary plus; returns the operand unchanged.
operator -(Float128) Float128 Unary negation; flips the sign bit.
operator ++(Float128) Float128 Adds one; correctly rounded.
operator --(Float128) Float128 Subtracts one; correctly rounded.
operator +(Float128, Float128) Float128 IEEE 754 addition.
operator -(Float128, Float128) Float128 IEEE 754 subtraction.
operator *(Float128, Float128) Float128 IEEE 754 multiplication.
operator /(Float128, Float128) Float128 IEEE 754 division.
operator %(Float128, Float128) Float128 Truncating remainder (C# % semantics).

Bitwise Operators

Operator Returns Description
operator &(Float128, Float128) Float128 Bitwise AND of the raw bit patterns.
operator |(Float128, Float128) Float128 Bitwise OR of the raw bit patterns.
operator ^(Float128, Float128) Float128 Bitwise XOR of the raw bit patterns.
operator ~(Float128) Float128 Bitwise complement of the raw bit pattern.

Comparison Operators

Operator Returns Description
operator ==(Float128, Float128) bool IEEE 754 equality; false if either operand is NaN.
operator !=(Float128, Float128) bool IEEE 754 inequality; true if either operand is NaN.
operator <(Float128, Float128) bool Less-than; false if either operand is NaN.
operator <=(Float128, Float128) bool Less-than-or-equal; false if either operand is NaN.
operator >(Float128, Float128) bool Greater-than; false if either operand is NaN.
operator >=(Float128, Float128) bool Greater-than-or-equal; false if either operand is NaN.

Implicit Conversion Operators (to Float128)

Operator Description
implicit operator Float128(sbyte) Widens a signed byte; exact.
implicit operator Float128(byte) Widens an unsigned byte; exact.
implicit operator Float128(short) Widens a 16-bit signed integer; exact.
implicit operator Float128(ushort) Widens a 16-bit unsigned integer; exact.
implicit operator Float128(int) Widens a 32-bit signed integer; exact.
implicit operator Float128(uint) Widens a 32-bit unsigned integer; exact.
implicit operator Float128(long) Widens a 64-bit signed integer; exact.
implicit operator Float128(ulong) Widens a 64-bit unsigned integer; exact.
implicit operator Float128(Int128) Widens a 128-bit signed integer; rounded for values exceeding 113 significant bits.
implicit operator Float128(UInt128) Widens a 128-bit unsigned integer; rounded for values exceeding 113 significant bits.
implicit operator Float128(char) Widens a char code-point; exact.
implicit operator Float128(Half) Widens a Half; exact (11-bit significand fits in 113 bits).
implicit operator Float128(float) Widens a float; exact (24-bit significand fits in 113 bits), preserving NaN payloads, infinities and subnormals.
implicit operator Float128(double) Widens a double; exact (53-bit significand fits in 113 bits), preserving NaN payloads, infinities and subnormals.
implicit operator Float128(decimal) Converts a decimal; exact (96-bit significand fits in 113 bits).

Explicit Conversion Operators (from Float128)

Operator Description
explicit operator sbyte(Float128) Truncates toward zero; saturates on overflow; returns 0 for NaN.
explicit operator checked sbyte(Float128) Throws OverflowException for NaN, infinity, or out-of-range.
explicit operator byte(Float128) Truncates toward zero; saturates on overflow; returns 0 for NaN.
explicit operator checked byte(Float128) Throws OverflowException for NaN, infinity, negative, or out-of-range.
explicit operator short(Float128) Truncates toward zero; saturates on overflow; returns 0 for NaN.
explicit operator checked short(Float128) Throws OverflowException for NaN, infinity, or out-of-range.
explicit operator ushort(Float128) Truncates toward zero; saturates on overflow; returns 0 for NaN.
explicit operator checked ushort(Float128) Throws OverflowException for NaN, infinity, negative, or out-of-range.
explicit operator int(Float128) Truncates toward zero; saturates on overflow; returns 0 for NaN.
explicit operator checked int(Float128) Throws OverflowException for NaN, infinity, or out-of-range.
explicit operator uint(Float128) Truncates toward zero; saturates on overflow; returns 0 for NaN.
explicit operator checked uint(Float128) Throws OverflowException for NaN, infinity, negative, or out-of-range.
explicit operator long(Float128) Truncates toward zero; saturates on overflow; returns 0 for NaN.
explicit operator checked long(Float128) Throws OverflowException for NaN, infinity, or out-of-range.
explicit operator ulong(Float128) Truncates toward zero; saturates on overflow; returns 0 for NaN.
explicit operator checked ulong(Float128) Throws OverflowException for NaN, infinity, negative, or out-of-range.
explicit operator Int128(Float128) Truncates toward zero; saturates on overflow; returns Int128.Zero for NaN.
explicit operator checked Int128(Float128) Throws OverflowException for NaN, infinity, or out-of-range.
explicit operator UInt128(Float128) Truncates toward zero; saturates on overflow; returns UInt128.Zero for NaN or negative.
explicit operator checked UInt128(Float128) Throws OverflowException for NaN, infinity, negative, or out-of-range.
explicit operator char(Float128) Truncates toward zero; saturates on overflow; returns (char)0 for NaN.
explicit operator checked char(Float128) Throws OverflowException for NaN, infinity, negative, or out-of-range.
explicit operator BigInteger(Float128) Truncates toward zero; exact for any finite integer.
explicit operator Half(Float128) Converts to the nearest Half (via double); may lose precision.
explicit operator float(Float128) Converts to the nearest float (via double); may lose precision.
explicit operator double(Float128) Converts to the nearest double; rounds to nearest, ties-to-even.
explicit operator decimal(Float128) Converts exactly from the binary significand and exponent, rounding once to nearest, ties-to-even, at the largest scale (up to 28) whose rounded 96-bit mantissa fits; trailing fractional zeros are removed, so the result carries its shortest scale. Magnitudes below 0.5E-28 (and negative zero) convert to 0. The result is the same on every target framework, and decimal values with up to 29 significant digits round-trip (for example, (decimal)(Float128)0.1m is 0.1m). Throws OverflowException for NaN, infinity, or once the magnitude rounds to 2^96.
explicit operator BigDecimal(Float128) Converts to an exact BigDecimal; throws OverflowException for NaN or infinity.
explicit operator Float128(BigDecimal) Converts a BigDecimal to the nearest Float128; saturates to ±infinity on overflow.
explicit operator Float128(BigInteger) Converts a BigInteger to the nearest Float128; saturates to ±infinity on overflow.

operator +(Float128) (unary)

public static Float128 operator +(Float128 value)

Returns value unchanged (identity operation).

operator -(Float128) (unary)

public static Float128 operator -(Float128 value)

Returns the negation of value by flipping the sign bit. Applies to all values including NaN and zero.

operator ++(Float128) (increment)

public static Float128 operator ++(Float128 value)

Returns value + 1, correctly rounded to nearest, ties-to-even.

operator --(Float128) (decrement)

public static Float128 operator --(Float128 value)

Returns value - 1, correctly rounded to nearest, ties-to-even.

operator +(Float128, Float128)

public static Float128 operator +(Float128 left, Float128 right)

Computes the IEEE 754 sum of left and right.

operator -(Float128, Float128)

public static Float128 operator -(Float128 left, Float128 right)

Computes the IEEE 754 difference of left and right.

operator *(Float128, Float128)

public static Float128 operator *(Float128 left, Float128 right)

Computes the IEEE 754 product of left and right.

operator /(Float128, Float128)

public static Float128 operator /(Float128 left, Float128 right)

Computes the IEEE 754 quotient of left and right.

operator %(Float128, Float128)

public static Float128 operator %(Float128 left, Float128 right)

Computes the truncating remainder of left divided by right (C# % semantics; the result has the same sign as left).

operator &(Float128, Float128)

public static Float128 operator &(Float128 left, Float128 right)

Returns the bitwise AND of the raw bit patterns of left and right. This is a raw bit manipulation; the result is not generally a meaningful floating-point value.

operator |(Float128, Float128)

public static Float128 operator |(Float128 left, Float128 right)

Returns the bitwise OR of the raw bit patterns of left and right.

operator ^(Float128, Float128)

public static Float128 operator ^(Float128 left, Float128 right)

Returns the bitwise XOR of the raw bit patterns of left and right.

operator ~(Float128) (bitwise complement)

public static Float128 operator ~(Float128 value)

Returns the bitwise complement of the raw bit pattern of value. The result is AllBitsSet when value is Zero.

operator ==(Float128, Float128)

public static bool operator ==(Float128 left, Float128 right)

Returns true when left and right are equal under IEEE 754 semantics: NaN is never equal to any value (including itself); positive zero equals negative zero.

operator !=(Float128, Float128)

public static bool operator !=(Float128 left, Float128 right)

Returns true when left and right are not equal under IEEE 754 semantics. Returns true when either operand is NaN.

operator <(Float128, Float128)

public static bool operator <(Float128 left, Float128 right)

Returns true when left is strictly less than right. Returns false if either operand is NaN.

operator <=(Float128, Float128)

public static bool operator <=(Float128 left, Float128 right)

Returns true when left is less than or equal to right. Returns false if either operand is NaN.

operator >(Float128, Float128)

public static bool operator >(Float128 left, Float128 right)

Returns true when left is strictly greater than right. Returns false if either operand is NaN.

operator >=(Float128, Float128)

public static bool operator >=(Float128 left, Float128 right)

Returns true when left is greater than or equal to right. Returns false if either operand is NaN.

See Also

ONIXLabs .NET Library


Clone this wiki locally