Struct Float80
An 80-bit extended-precision binary floating-point number, as an x87 floating-point unit computes with: a sign, a 15-bit exponent and a 64-bit significand, rounded to nearest, ties to even.
public readonly struct Float80 : IEquatable<Float80>
- Implements
- Inherited Members
Remarks
MS-VBAL 5.6.9.3 lets an implementation "perform floating point operations with a higher-precision than the effective value type
(such as an 'extended' or 'long double' type)", and MS-VBA does: an expression of Single and Double operands is computed in this format,
and its value is rounded to the effective type where it is stored. So (1E+308 * 10) / 10 is 1E+308 with no overflow, and
0.1 + 0.2 - 0.3 is 2.77555756156289E-17, where an evaluation in Double gives 5.55111512312578E-17.
Every operation is correctly rounded, as IEEE 754 requires of the basic operations, and reports the FloatingPointExceptions it signals;
a NaN produced by an invalid operation is the x87's default NaN (the "real indefinite", negative, which VBA writes -nan(ind)), and an
operation of a NaN gives that NaN back, made quiet. Rounding to double or float (ToDouble(out FloatingPointExceptions),
ToSingle(out FloatingPointExceptions)) is what storing the value in a variable of that type does: it is a second rounding, of the value already rounded to 64 bits.
Properties
Indefinite
The NaN an invalid operation produces: the x87's "real indefinite", a negative quiet NaN, which VBA writes -nan(ind).
public static Float80 Indefinite { get; }
Property Value
IsFinite
Whether the value is a number: neither an infinity nor a NaN.
public bool IsFinite { get; }
Property Value
IsInfinity
Whether the value is an infinity, of either sign.
public bool IsInfinity { get; }
Property Value
IsNaN
Whether the value is a NaN.
public bool IsNaN { get; }
Property Value
IsNegative
Whether the sign bit is set: a negative number, negative zero, or a NaN whose sign is negative.
public bool IsNegative { get; }
Property Value
IsZero
Whether the value is zero, of either sign.
public bool IsZero { get; }
Property Value
NegativeInfinity
Negative infinity.
public static Float80 NegativeInfinity { get; }
Property Value
PositiveInfinity
Positive infinity.
public static Float80 PositiveInfinity { get; }
Property Value
SignAndExponent
The sign bit (bit 15) and the biased exponent (bits 0-14) of the value, as the x87 format encodes them.
public ushort SignAndExponent { get; }
Property Value
Significand
The 64-bit significand of the value, with its explicit integer bit (bit 63), as the x87 format encodes it.
public ulong Significand { get; }
Property Value
Zero
Positive zero.
public static Float80 Zero { get; }
Property Value
Methods
Abs()
The value with its sign cleared. A NaN's sign is cleared too, with no exception.
public Float80 Abs()
Returns
Add(Float80, Float80, out FloatingPointExceptions)
The sum of two values, correctly rounded.
public static Float80 Add(Float80 a, Float80 b, out FloatingPointExceptions exceptions)
Parameters
aFloat80The augend.
bFloat80The addend.
exceptionsFloatingPointExceptionsThe exceptions the operation signals: Invalid for infinities of opposite signs.
Returns
Compare(Float80, Float80)
Compares two values as IEEE 754 orders them: negative and positive zero are equal, and a NaN is ordered with nothing.
public static int? Compare(Float80 a, Float80 b)
Parameters
Returns
- int?
A negative number, zero or a positive number as
ais less than, equal to or greater thanb; or null when either is a NaN.
Divide(Float80, Float80, out FloatingPointExceptions)
The quotient of two values, correctly rounded.
public static Float80 Divide(Float80 a, Float80 b, out FloatingPointExceptions exceptions)
Parameters
aFloat80The dividend.
bFloat80The divisor.
exceptionsFloatingPointExceptionsThe exceptions the operation signals: Invalid for zero divided by zero and infinity divided by infinity, DivideByZero for any other finite number divided by zero, Overflow past the range of the format.
Returns
Equals(Float80)
Whether two values have the same encoding: a bitwise comparison, under which a NaN equals itself and the two zeros differ.
public bool Equals(Float80 other)
Parameters
otherFloat80
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
FromCurrency(long)
The value of a Currency: its ten-thousandths divided by 10,000, rounded once.
public static Float80 FromCurrency(long scaled)
Parameters
scaledlongThe value of the
Currency, in ten-thousandths.
Returns
FromDouble(double)
The value of a double, exactly: every Double is a value of this format.
public static Float80 FromDouble(double value)
Parameters
valuedoubleThe value to convert.
Returns
FromInt64(long)
The value of a 64-bit integer, exactly: the significand holds every LongLong.
public static Float80 FromInt64(long value)
Parameters
valuelongThe value to convert.
Returns
FromSingle(float)
The value of a float, exactly: every Single is a value of this format.
public static Float80 FromSingle(float value)
Parameters
valuefloatThe value to convert.
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Multiply(Float80, Float80, out FloatingPointExceptions)
The product of two values, correctly rounded.
public static Float80 Multiply(Float80 a, Float80 b, out FloatingPointExceptions exceptions)
Parameters
aFloat80The multiplicand.
bFloat80The multiplier.
exceptionsFloatingPointExceptionsThe exceptions the operation signals: Invalid for zero times infinity, Overflow past the range of the format.
Returns
Negate()
The value with its sign inverted. A NaN is negated too, with no exception.
public Float80 Negate()
Returns
RoundToDoublePrecision()
The value rounded to the 53 bits of a Double's significand, in the range of this format: what the x87 does to a value it keeps, with its
precision control set to double precision. No value overflows.
public Float80 RoundToDoublePrecision()
Returns
RoundToIntegral(MidpointRounding)
The integer the value rounds to - to nearest, ties to even (ToEven); toward zero
(ToZero, VBA's Fix); toward negative infinity (ToNegativeInfinity, VBA's
Int); or toward positive infinity (ToPositiveInfinity). An infinity, a NaN and zero are themselves.
public Float80 RoundToIntegral(MidpointRounding mode)
Parameters
modeMidpointRoundingThe direction of the rounding.
Returns
RoundToSinglePrecision()
The value rounded to the 24 bits of a Single's significand, in the range of this format. No value overflows.
public Float80 RoundToSinglePrecision()
Returns
Subtract(Float80, Float80, out FloatingPointExceptions)
The difference of two values, correctly rounded.
public static Float80 Subtract(Float80 a, Float80 b, out FloatingPointExceptions exceptions)
Parameters
aFloat80The minuend.
bFloat80The subtrahend.
exceptionsFloatingPointExceptionsThe exceptions the operation signals: Invalid for infinities of the same sign.
Returns
ToDouble(out FloatingPointExceptions)
The value rounded to a double, to nearest, ties to even: what storing it in a Double does. A value past the range of a
Double is an infinity, and signals Overflow; a NaN keeps its sign and the high bits of its payload.
public double ToDouble(out FloatingPointExceptions exceptions)
Parameters
exceptionsFloatingPointExceptionsThe exceptions the rounding signals.
Returns
ToSingle(out FloatingPointExceptions)
The value rounded to a float, to nearest, ties to even: what storing it in a Single does. A value past the range of a
Single is an infinity, and signals Overflow.
public float ToSingle(out FloatingPointExceptions exceptions)
Parameters
exceptionsFloatingPointExceptionsThe exceptions the rounding signals.
Returns
ToString()
The value rounded to a double, and its encoding.
public override string ToString()
Returns
TryToInt64(out long)
The value as a 64-bit integer, when it is an integer of that range.
public bool TryToInt64(out long value)
Parameters
valuelongThe integer, or 0.