PeterO.ExtendedFloat
PeterO.ExtendedFloat
public sealed class ExtendedFloat : System.IEquatable, System.IComparable
Deprecated. Use EFloat from PeterO.Numbers/com.upokecenter.numbers and the output of this class's ToString method.
This class is largely obsolete. It will be replaced by a new version of this class in a different namespace/package and library, called PeterO.Numbers.EFloat
in the PeterO.Numbers
library (in .NET), or com.upokecenter.numbers.EFloat
in the com.github.peteroupc/numbers
artifact (in Java). This new class can be used in the CBORObject.FromObject(object)
method (by including the new library in your code, among other things).
Represents an arbitrary-precision binary floating-point number. Consists of an integer mantissa and an integer exponent, both arbitrary-precision. The value of the number equals mantissa * 2^exponent. This class also supports values for negative zero, not-a-number (NaN) values, and infinity.
Passing a signaling NaN to any arithmetic operation shown here will signal the flag FlagInvalid and return a quiet NaN, even if another operand to that operation is a quiet NaN, unless noted otherwise.
Passing a quiet NaN to any arithmetic operation shown here will return a quiet NaN, unless noted otherwise.
Unless noted otherwise,passing a null arbitrary-precision binary float argument to any method here will throw an exception.
When an arithmetic operation signals the flag FlagInvalid, FlagOverflow, or FlagDivideByZero, it will not throw an exception too, unless the operation's trap is enabled in the precision context (see PrecisionContext's Traps property).
An arbitrary-precision binary float value can be serialized in one of the following ways:
By calling the toString() method. However, not all strings can be converted back to an arbitrary-precision binary float without loss, especially if the string has a fractional part.
By calling the UnsignedMantissa, Exponent, and IsNegative properties, and calling the IsInfinity, IsQuietNaN, and IsSignalingNaN methods. The return values combined will uniquely identify a particular arbitrary-precision binary float value.
If an operation requires creating an intermediate value that might be too big to fit in memory (or might require more than 2 gigabytes of memory to store -- due to the current use of a 32-bit integer internally as a length), the operation may signal an invalid-operation flag and return not-a-number (NaN). In certain rare cases, the CompareTo method may throw OutOfMemoryException (called OutOfMemoryError in Java) in the same circumstances.
Thread safety: Instances of this class are immutable, so they are inherently safe for use by multiple threads. Multiple instances of this object with the same properties are interchangeable, so they should not be compared using the "==" operator (which might only check if each side of the operator is the same instance).
Member Summary
CompareTo(PeterO.ExtendedFloat)
- Compares this extended float to another.Create(int, int)
- Creates a number with the value exponent*2^mantissa.Create(PeterO.BigInteger, PeterO.BigInteger)
- Creates a number with the value exponent*2^mantissa.Equals(object)
- Determines whether this object's mantissa and exponent are equal to those of another object and that other object is an arbitrary-precision decimal number.Equals(PeterO.ExtendedFloat)
- Determines whether this object's mantissa and exponent are equal to those of another object.EqualsInternal(PeterO.ExtendedFloat)
- Determines whether this object's mantissa and exponent are equal to those of another object.Exponent
- Gets this object's exponent.FromString(string)
- Creates a binary float from a text string that represents a number.FromString(string, int, int, PeterO.PrecisionContext)
- Creates a binary float from a text string that represents a number.GetHashCode()
- Calculates this object's hash code.IsInfinity()
- Gets a value indicating whether this object is positive or negative infinity.IsNaN()
- Returns whether this object is a not-a-number value.IsNegative
- Gets a value indicating whether this object is negative, including negative zero.IsNegativeInfinity()
- Returns whether this object is negative infinity.IsPositiveInfinity()
- Returns whether this object is positive infinity.IsQuietNaN()
- Gets a value indicating whether this object is a quiet not-a-number value.IsSignalingNaN()
- Gets a value indicating whether this object is a signaling not-a-number value.Mantissa
- Gets this object's un-scaled value.public static readonly PeterO.ExtendedFloat NaN;
- A not-a-number value.public static readonly PeterO.ExtendedFloat NegativeInfinity;
- Negative infinity, less than any other number.public static readonly PeterO.ExtendedFloat NegativeZero;
- Represents the number negative zero.public static readonly PeterO.ExtendedFloat One;
- Represents the number 1.public static readonly PeterO.ExtendedFloat PositiveInfinity;
- Positive infinity, greater than any other number.Sign
- Gets this value's sign: -1 if negative; 1 if positive; 0 if zero.public static readonly PeterO.ExtendedFloat SignalingNaN;
- A not-a-number value that signals an invalid operation flag when it's passed as an argument to any arithmetic operation in arbitrary-precision binary float.public static readonly PeterO.ExtendedFloat Ten;
- Represents the number 10.ToString()
- Converts this value to a string.UnsignedMantissa
- Gets the absolute value of this object's un-scaled value.public static readonly PeterO.ExtendedFloat Zero;
- Represents the number 0.
NaN
public static readonly PeterO.ExtendedFloat NaN;
A not-a-number value.
NegativeInfinity
public static readonly PeterO.ExtendedFloat NegativeInfinity;
Negative infinity, less than any other number.
NegativeZero
public static readonly PeterO.ExtendedFloat NegativeZero;
Represents the number negative zero.
One
public static readonly PeterO.ExtendedFloat One;
Represents the number 1.
PositiveInfinity
public static readonly PeterO.ExtendedFloat PositiveInfinity;
Positive infinity, greater than any other number.
SignalingNaN
public static readonly PeterO.ExtendedFloat SignalingNaN;
A not-a-number value that signals an invalid operation flag when it's passed as an argument to any arithmetic operation in arbitrary-precision binary float.
Ten
public static readonly PeterO.ExtendedFloat Ten;
Represents the number 10.
Zero
public static readonly PeterO.ExtendedFloat Zero;
Represents the number 0.
Exponent
public PeterO.BigInteger Exponent { get; }
Gets this object's exponent. This object's value will be an integer if the exponent is positive or zero.
Returns:
This object's exponent. This object's value will be an integer if the exponent is positive or zero.
IsNegative
public bool IsNegative { get; }
Deprecated. Use EFloat from PeterO.Numbers/com.upokecenter.numbers.
Gets a value indicating whether this object is negative, including negative zero.
Returns:
true
If this object is negative, including negative zero; otherwise, . false
.
Mantissa
public PeterO.BigInteger Mantissa { get; }
Gets this object's un-scaled value.
Returns:
This object's un-scaled value. Will be negative if this object's value is negative (including a negative NaN).
Sign
public int Sign { get; }
Deprecated. Use EFloat from PeterO.Numbers/com.upokecenter.numbers.
Gets this value's sign: -1 if negative; 1 if positive; 0 if zero.
Returns:
This value's sign: -1 if negative; 1 if positive; 0 if zero.
UnsignedMantissa
public PeterO.BigInteger UnsignedMantissa { get; }
Gets the absolute value of this object's un-scaled value.
Returns:
The absolute value of this object's un-scaled value.
CompareTo
public sealed int CompareTo( PeterO.ExtendedFloat other);
Compares this extended float to another.
Parameters:
- other: An extended float to compare this one with.
Return Value:
Less than 0 if this value is less than, 0 if equal to, or greater than 0 if greater than the other value.
Create
public static PeterO.ExtendedFloat Create( int mantissaSmall, int exponentSmall);
Creates a number with the value exponent*2^mantissa.
Parameters:
mantissaSmall: The un-scaled value.
exponentSmall: The binary exponent.
Return Value:
An arbitrary-precision binary float.
Create
public static PeterO.ExtendedFloat Create( PeterO.BigInteger mantissa, PeterO.BigInteger exponent);
Creates a number with the value exponent*2^mantissa.
Parameters:
mantissa: The un-scaled value.
exponent: The binary exponent.
Return Value:
An arbitrary-precision binary float.
Exceptions:
- System.ArgumentNullException: The parameter mantissa or exponent is null.
Equals
public override bool Equals( object obj);
Determines whether this object's mantissa and exponent are equal to those of another object and that other object is an arbitrary-precision decimal number.
Parameters:
- obj: The parameter obj is an arbitrary object.
Return Value:
true
if the objects are equal; otherwise, false
.
Equals
public sealed bool Equals( PeterO.ExtendedFloat other);
Deprecated. Use EFloat from PeterO.Numbers/com.upokecenter.numbers.
Determines whether this object's mantissa and exponent are equal to those of another object.
Parameters:
- other: An arbitrary-precision binary float.
Return Value:
true
if this object's mantissa and exponent are equal to those of another object; otherwise, false
.
Exceptions:
- System.ArgumentNullException: The parameter other is null.
EqualsInternal
public bool EqualsInternal( PeterO.ExtendedFloat otherValue);
Deprecated. Use EFloat from PeterO.Numbers/com.upokecenter.numbers.
Determines whether this object's mantissa and exponent are equal to those of another object.
Parameters:
- otherValue: An arbitrary-precision binary float.
Return Value:
true
if this object's mantissa and exponent are equal to those of another object; otherwise, false
.
Exceptions:
- System.ArgumentNullException: The parameter otherValue is null.
FromString
public static PeterO.ExtendedFloat FromString( string str);
Creates a binary float from a text string that represents a number.
Parameters:
- str: A text string containing the number to convert.
Return Value:
The parsed number, converted to arbitrary-precision binary float.
FromString
public static PeterO.ExtendedFloat FromString( string str, int offset, int length, PeterO.PrecisionContext ctx);
Deprecated. Use EFloat from PeterO.Numbers/com.upokecenter.numbers.
Creates a binary float from a text string that represents a number. Note that if the string contains a negative exponent, the resulting value might not be exact, in which case the resulting binary float will be an approximation of this decimal number's value. (NOTE: This documentation previously said the binary float will contain enough precision to accurately convert it to a 32-bit or 64-bit floating point number. Due to double rounding, this will generally not be the case for certain numbers converted from decimal to ExtendedFloat via this method and in turn converted to double
or float
.) The format of the string generally consists of:
An optional plus sign ("+" , U+002B) or minus sign ("-", U+002D) (if '-' , the value is negative.)
One or more digits, with a single optional decimal point after the first digit and before the last digit.
Optionally, "E+"/"e+" (positive exponent) or "E-"/"e-" (negative exponent) plus one or more digits specifying the exponent.
The string can also be "-INF", "-Infinity", "Infinity", "INF", quiet NaN ("NaN") followed by any number of digits, or signaling NaN ("sNaN") followed by any number of digits, all in any combination of upper and lower case.
All characters mentioned above are the corresponding characters in the Basic Latin range. In particular, the digits must be the basic digits 0 to 9 (U+0030 to U+0039). The string is not allowed to contain white space characters, including spaces.
Parameters:
str: The parameter str is a text string.
offset: A zero-based index showing where the desired portion of str begins.
length: The length, in code units, of the desired portion of str (but not more than str 's length).
ctx: A PrecisionContext object specifying the precision, rounding, and exponent range to apply to the parsed number. Can be null.
Return Value:
The parsed number, converted to arbitrary-precision binary float.
Exceptions:
System.ArgumentNullException: The parameter str is null.
System.ArgumentException: Either offset or length is less than 0 or greater than str 's length, or str ' s length minus offset is less than length .
GetHashCode
public override int GetHashCode();
Calculates this object's hash code. No application or process IDs are used in the hash code calculation.
Return Value:
This object's hash code.
IsInfinity
public bool IsInfinity();
Gets a value indicating whether this object is positive or negative infinity.
Return Value:
true
if this object is positive or negative infinity; otherwise, false
.
IsNaN
public bool IsNaN();
Returns whether this object is a not-a-number value.
Return Value:
true
if this object is a not-a-number value; otherwise, false
.
IsNegativeInfinity
public bool IsNegativeInfinity();
Deprecated. Use EFloat from PeterO.Numbers/com.upokecenter.numbers.
Returns whether this object is negative infinity.
Return Value:
true
if this object is negative infinity; otherwise, false
.
IsPositiveInfinity
public bool IsPositiveInfinity();
Deprecated. Use EFloat from PeterO.Numbers/com.upokecenter.numbers.
Returns whether this object is positive infinity.
Return Value:
true
if this object is positive infinity; otherwise, false
.
IsQuietNaN
public bool IsQuietNaN();
Deprecated. Use EFloat from PeterO.Numbers/com.upokecenter.numbers.
Gets a value indicating whether this object is a quiet not-a-number value.
Return Value:
true
if this object is a quiet not-a-number value; otherwise, false
.
IsSignalingNaN
public bool IsSignalingNaN();
Deprecated. Use EFloat from PeterO.Numbers/com.upokecenter.numbers.
Gets a value indicating whether this object is a signaling not-a-number value.
Return Value:
true
if this object is a signaling not-a-number value; otherwise, false
.
ToString
public override string ToString();
Converts this value to a string.
Return Value:
A string representation of this object. The value is converted to decimal and the decimal form of this number's value is returned.