[Serializable] |
Single complies with the IEC 60559:1989 (IEEE 754) standard for binary floating-point arithmetic.
Single provides methods to compare instances of this type, convert the value of an instance to its string representation, and convert the string representation of a number to an instance of this type.
For information about how format specification codes control the string representation of value types, see the conceptual topic at MSDN: formattingoverview.
This type implements interfaces IComparable, IFormattable, and IConvertible. Use the Convert class for conversions instead of this type's explicit interface member implementation of IConvertible.When performing binary operations, if one of the operands is a floating-point type, Single or Double, then the other operand is required to be an integral type or a floating-point type. The operation is evaluated as follows:
The floating-point operators, including the assignment operators, do not throw exceptions. Instead, in exceptional situations, the result of a floating-point operation is zero, infinity, or NaN, as described below:
Epsilon | Represents the smallest positive Single greater than zero. This field is constant. |
MaxValue | Represents the largest possible value of Single. This field is constant. |
MinValue | Represents the smallest possible value of Single. This field is constant. |
NaN | Represents not a number (NaN). This field is constant. |
NegativeInfinity | Represents negative infinity. This field is constant. |
PositiveInfinity | Represents positive infinity. This field is constant. |
CompareTo | Compares this instance to a specified object and returns an indication of their relative values. |
Equals | Overridden: Returns a value indicating whether this instance is equal to a specified object. |
GetHashCode | Overridden: Returns the hash code for this instance. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
GetTypeCode | Returns the TypeCode for value type Single. |
IsInfinity | Returns a value indicating whether the specified number evaluates to negative or positive infinity. |
IsNaN | Returns a value indicating whether the specified number evaluates to not a number ( Single.NaN). |
IsNegativeInfinity | Returns a value indicating whether the specified number evaluates to negative infinity. |
IsPositiveInfinity | Returns a value indicating whether the specified number evaluates to positive infinity. |
Parse | Overloaded:Parse(string s) Converts the string representation of a number to its single-precision floating point number equivalent. |
Parse | Overloaded:Parse(string s, IFormatProvider provider) Converts the string representation of a number in a specified culture-specific format to its single-precision floating point number equivalent. |
Parse | Overloaded:Parse(string s, NumberStyles style) Converts the string representation of a number in a specified style to its single-precision floating point number equivalent. |
Parse | Overloaded:Parse(string s, NumberStyles style, IFormatProvider provider) Converts the string representation of a number in a specified style and culture-specific format to its single-precision floating point number equivalent. |
ToString | Overloaded:ToString() Overridden: Converts the numeric value of this instance to its equivalent string representation. |
ToString | Overloaded:ToString(IFormatProvider provider) Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information. |
ToString | Overloaded:ToString(string format) Converts the numeric value of this instance to its equivalent string representation, using the specified format. |
ToString | Overloaded:ToString(string format, IFormatProvider provider) Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public const float Epsilon;
|
Two apparently equivalent floating point numbers might not compare equal because of differences in their least significant digits. For example, the C# expression,
(float)1/3 == (float)0.33333
, does not compare equal because the division operation on the left-hand side has maximum precision while the constant on the right-hand side is only precise to the visible digits.
Instead, determine if the two sides of a comparison are close enough to equal for your purposes by comparing whether the absolute value of the difference between the left and right-hand sides is less than Epsilon.
public const float MaxValue;
|
public const float MinValue;
|
public const float NaN;
|
This constant is returned when the result of an operation is undefined.
Use Single.IsNaN to determine whether a value is not a number. It is not possible to determine whether a value is not a number by comparing it to another value equal to NaN.
public const float NegativeInfinity;
|
This constant is returned when the result of an operation is less than Single.MinValue.
Use Single.IsNegativeInfinity to determine whether a value evaluates to negative infinity. It is not possible to determine whether a value evaluates to negative infinity by comparing it to another value equal to NegativeInfinity.
public const float PositiveInfinity;
|
This constant is returned when the result of an operation is greater than Single.MaxValue.
Use Single.IsPositiveInfinity to determine whether a value evaluates to positive infinity. It is not possible to determine whether a value evaluates to positive infinity by comparing it to another value equal to PositiveInfinity.
value
Return Value | Description |
---|---|
Less than zero | This instance is less than value. -or- This instance is not a number ( Single.NaN) and value is a number. |
Zero | This instance is equal to value. -or- This instance and value are both not a number ( Single.NaN), Single.PositiveInfinity, or Single.NegativeInfinity. |
Greater than zero | This instance is greater than value. -or- This instance is a number and value is not a number ( Single.NaN). -or- value is null. |
Exception Type | Condition |
---|---|
ArgumentException | value is not a Single or null. |
The value parameter must be null or an instance of Single; otherwise, an exception is thrown.
This method is implemented to support the IComparable interface. Note that, although a Single.NaN is not considered to be equal to another Single.NaN (even itself), the IComparable interface requires that
A.CompareTo(A)
return zero.
obj
~Single(); |
public override int GetHashCode(); |
public Type GetType(); |
public TypeCode GetTypeCode(); |
f
f
f
f
protected object MemberwiseClone(); |
s
Exception Type | Condition |
---|---|
ArgumentNullException | s is null. |
FormatException | s is not a number in a valid format. |
OverflowException | s represents a number less than Single.MinValue or greater than Single.MaxValue. |
[ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]
Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.
Some examples of s are "100", "-123,456,789", "123.45+e6", "+500", "5e2", "3.1416", "600.", "-.123", and "-Infinity".
This version of Parse uses the NumberStyles values, NumberStyles.Float and NumberStyles.AllowThousands, and the culture-specific NumberFormatInfo data associated with the current thread.
For more information about numeric formats, see the the conceptual topic at MSDN: formattingoverview topic.
public static float Parse( |
s
provider
Exception Type | Condition |
---|---|
ArgumentNullException | s is null. |
FormatException | s is not a number in a valid format. |
OverflowException | s represents a number less than Single.MinValue or greater than Single.MaxValue. |
[ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]
Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.
Some examples of s are "100", "-123,456,789", "123.45+e6", "+500", "5e2", "3.1416", "600.", "-.123", and "-Infinity".
This version of Parse uses the NumberStyles values, NumberStyles.Float and NumberStyles.AllowThousands, and the specified number format information. If provider is null or a NumberFormatInfo cannot be obtained, the formatting information for the current system culture is used.
For more information about numeric formats, see the the conceptual topic at MSDN: formattingoverview topic.
public static float Parse( |
s
style
Exception Type | Condition |
---|---|
ArgumentNullException | s is null. |
FormatException | s is not a number in a valid format. |
OverflowException | s represents a number less than Single.MinValue or greater than Single.MaxValue. |
[ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]
Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.
Some examples of s are "100", "-123,456,789", "123.45+e6", "+500", "5e2", "3.1416", "600.", "-.123", and "-Infinity".
This version of Parse uses the specified NumberStyles and the culture-specific NumberFormatInfo data associated with the current thread.
For more information about numeric formats, see the the conceptual topic at MSDN: formattingoverview topic.
public static float Parse( |
s
style
provider
Exception Type | Condition |
---|---|
ArgumentNullException | s is null. |
FormatException | s is not a numeric value. |
ArgumentException | style is not a combination of bit flags from the NumberStyles enumeration. |
[ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]
Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.
Some examples of s are "100", "-123,456,789", "123.45+e6", "+500", "5e2", "3.1416", "600.", "-.123", and "-Infinity".
This version of Parse uses the specified NumberStyles and the specified number format information. If provider is null or a NumberFormatInfo cannot be obtained, the formatting information for the current system culture is used.
For more information about numeric formats, see the the conceptual topic at MSDN: formattingoverview topic.
public override string ToString(); |
[sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits]
Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.
Some examples of the return value are "100", "-123,456,789", "123.45+e6", "500", "3.1416", "600", "-0.123", and "-Infinity".
This version of ToString uses the general format specifier ("G") and the NumberFormatInfo for the current culture.
public string ToString( |
provider
[sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits]
Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.
Some examples of the return value are "100", "-123,456,789", "123.45+e6", "500", "3.1416", "600", "-0.123", and "-Infinity".
This instance is formatted with the general format specifier ("G").
The provider parameter is an IFormatProvider that obtains a NumberFormatInfo that supplies culture-specific format information. If provider is null, the return value is formatted with NumberFormatInfo data for the current culture.
format
Exception Type | Condition |
---|---|
FormatException | format is invalid. |
[sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits]
Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.
Some examples of the return value are "100", "-123,456,789", "123.45+e6", "500", "3.1416", "600", "-0.123", and "-Infinity".
If format is null or an empty string, the return value is formatted with the general format specifier ("G").
By default, the return value only contains 7 digits of precision although a maximum of 9 digits is maintained internally. If the value of this instance has greater than 7 digits, ToString returns NumberFormatInfo.PositiveInfinitySymbol or NumberFormatInfo.NegativeInfinitySymbol instead of the expected number. If you require more precision, specify format with the "G9" format specification, which always returns 9 digits of precision, or "R", which returns 7 digits if the number can be represented with that precision or 9 digits if the number can only be represented with maximum precision.
The return value is formatted with NumberFormatInfo data for the current culture.
public string ToString( |
format
provider
[sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits]
Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.
Some examples of the return value are "100", "-123,456,789", "123.45+e6", "500", "3.1416", "600", "-0.123", and "-Infinity".
If format is null or an empty string, the return value for this instance is formatted with the general format specifier ("G").
By default, the return value only contains 7 digits of precision although a maximum of 9 digits is maintained internally. If the value of this instance has greater than 7 digits, ToString returns NumberFormatInfo.PositiveInfinitySymbol or NumberFormatInfo.NegativeInfinitySymbol instead of the expected number. If you require more precision, specify format with the "G9" format specification, which always returns 9 digits of precision, or "R", which returns 7 digits if the number can be represented with that precision or 9 digits if the number can only be represented with maximum precision.
The provider parameter is an IFormatProvider that obtains a NumberFormatInfo that supplies culture-specific format information. If provider is null, the return value is formatted with NumberFormatInfo data for the current culture.