Skip to main content
.NET Framework Class Library
Single Structure

Represents a single-precision floating-point number.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)
Syntax
<[%$TOPIC/3www918f_en-us_VS_110_1_0_0_0_0%]> _
<[%$TOPIC/3www918f_en-us_VS_110_1_0_0_0_1%](True)> _
Public Structure Single _
	Implements [%$TOPIC/3www918f_en-us_VS_110_1_0_0_0_2%], [%$TOPIC/3www918f_en-us_VS_110_1_0_0_0_3%], [%$TOPIC/3www918f_en-us_VS_110_1_0_0_0_4%], [%$TOPIC/3www918f_en-us_VS_110_1_0_0_0_5%](Of Single),  _
	[%$TOPIC/3www918f_en-us_VS_110_1_0_0_0_6%](Of Single)
[[%$TOPIC/3www918f_en-us_VS_110_1_0_1_0_0%]]
[[%$TOPIC/3www918f_en-us_VS_110_1_0_1_0_1%](true)]
public struct Single : [%$TOPIC/3www918f_en-us_VS_110_1_0_1_0_2%], [%$TOPIC/3www918f_en-us_VS_110_1_0_1_0_3%], 
	[%$TOPIC/3www918f_en-us_VS_110_1_0_1_0_4%], [%$TOPIC/3www918f_en-us_VS_110_1_0_1_0_5%]<float>, [%$TOPIC/3www918f_en-us_VS_110_1_0_1_0_6%]<float>
[[%$TOPIC/3www918f_en-us_VS_110_1_0_2_0_0%]]
[[%$TOPIC/3www918f_en-us_VS_110_1_0_2_0_1%](true)]
public value class Single : [%$TOPIC/3www918f_en-us_VS_110_1_0_2_0_2%], 
	[%$TOPIC/3www918f_en-us_VS_110_1_0_2_0_3%], [%$TOPIC/3www918f_en-us_VS_110_1_0_2_0_4%], [%$TOPIC/3www918f_en-us_VS_110_1_0_2_0_5%]<float>, [%$TOPIC/3www918f_en-us_VS_110_1_0_2_0_6%]<float>
[<[%$TOPIC/3www918f_en-us_VS_110_1_0_3_0_0%]>]
[<[%$TOPIC/3www918f_en-us_VS_110_1_0_3_0_1%]>]
[<[%$TOPIC/3www918f_en-us_VS_110_1_0_3_0_2%](true)>]
type Single =  
    struct 
        interface [%$TOPIC/3www918f_en-us_VS_110_1_0_3_0_3%] 
        interface [%$TOPIC/3www918f_en-us_VS_110_1_0_3_0_4%] 
        interface [%$TOPIC/3www918f_en-us_VS_110_1_0_3_0_5%] 
        interface [%$TOPIC/3www918f_en-us_VS_110_1_0_3_0_6%]<float32>
        interface [%$TOPIC/3www918f_en-us_VS_110_1_0_3_0_7%]<float32>
    end

The Single type exposes the following members.

Methods
  NameDescription
Public method Supported by the XNA Framework CompareTo(Object)Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps CompareTo(Single)Compares this instance to a specified single-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified single-precision floating-point number.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Equals(Object)Returns a value indicating whether this instance is equal to a specified object. (Overrides ValueTypeEquals(Object).)
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Equals(Single)Returns a value indicating whether this instance and a specified Single object represent the same value.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetHashCodeReturns the hash code for this instance. (Overrides ValueTypeGetHashCode.)
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method Supported by the XNA Framework GetTypeCodeReturns the TypeCode for value type Single.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps IsInfinityReturns a value indicating whether the specified number evaluates to negative or positive infinity.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps IsNaNReturns a value that indicates whether the specified value is not a number ( NaN).
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps IsNegativeInfinityReturns a value indicating whether the specified number evaluates to negative infinity.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps IsPositiveInfinityReturns a value indicating whether the specified number evaluates to positive infinity.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Parse(String)Converts the string representation of a number to its single-precision floating-point number equivalent.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Parse(String, NumberStyles)Converts the string representation of a number in a specified style to its single-precision floating-point number equivalent.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Parse(String, IFormatProvider)Converts the string representation of a number in a specified culture-specific format to its single-precision floating-point number equivalent.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Parse(String, NumberStyles, IFormatProvider)Converts the string representation of a number in a specified style and culture-specific format to its single-precision floating-point number equivalent.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToStringConverts the numeric value of this instance to its equivalent string representation. (Overrides ValueTypeToString.)
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToString(IFormatProvider)Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToString(String)Converts the numeric value of this instance to its equivalent string representation, using the specified format.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToString(String, IFormatProvider)Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.
Public method Static member Supported by Portable Class Library Supported in .NET for Windows Store apps TryParse(String, Single)Converts the string representation of a number to its single-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.
Public method Static member Supported by Portable Class Library Supported in .NET for Windows Store apps TryParse(String, NumberStyles, IFormatProvider, Single)Converts the string representation of a number in a specified style and culture-specific format to its single-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.
Top
Operators
  NameDescription
Public operator Static member Supported by Portable Class Library Supported in .NET for Windows Store apps EqualityReturns a value that indicates whether two specified Single values are equal.
Public operator Static member Supported by Portable Class Library Supported in .NET for Windows Store apps GreaterThanReturns a value that indicates whether a specified Single value is greater than another specified Single value.
Public operator Static member Supported by Portable Class Library Supported in .NET for Windows Store apps GreaterThanOrEqualReturns a value that indicates whether a specified Single value is greater than or equal to another specified Single value.
Public operator Static member Supported by Portable Class Library Supported in .NET for Windows Store apps InequalityReturns a value that indicates whether two specified Single values are not equal.
Public operator Static member Supported by Portable Class Library Supported in .NET for Windows Store apps LessThanReturns a value that indicates whether a specified Single value is less than another specified Single value.
Public operator Static member Supported by Portable Class Library Supported in .NET for Windows Store apps LessThanOrEqualReturns a value that indicates whether a specified Single value is less than or equal to another specified Single value.
Top
Fields
  NameDescription
Public field Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps EpsilonRepresents the smallest positive Single value that is greater than zero. This field is constant.
Public field Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps MaxValueRepresents the largest possible value of Single. This field is constant.
Public field Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps MinValueRepresents the smallest possible value of Single. This field is constant.
Public field Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps NaNRepresents not a number (NaN). This field is constant.
Public field Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps NegativeInfinityRepresents negative infinity. This field is constant.
Public field Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps PositiveInfinityRepresents positive infinity. This field is constant.
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method Supported by Portable Class Library Supported in .NET for Windows Store apps IComparableCompareToCompares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToBooleanInfrastructure. For a description of this member, see IConvertibleToBoolean.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToByteInfrastructure. For a description of this member, see IConvertibleToByte.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToCharInfrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToDateTimeInfrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToDecimalInfrastructure. For a description of this member, see IConvertibleToDecimal.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToDoubleInfrastructure. For a description of this member, see IConvertibleToDouble.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToInt16Infrastructure. For a description of this member, see IConvertibleToInt16.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToInt32Infrastructure. For a description of this member, see IConvertibleToInt32.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToInt64Infrastructure. For a description of this member, see IConvertibleToInt64.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToSByteInfrastructure. For a description of this member, see IConvertibleToSByte.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToSingleInfrastructure. For a description of this member, see IConvertibleToSingle.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToTypeInfrastructure. For a description of this member, see IConvertibleToType.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToUInt16Infrastructure. For a description of this member, see IConvertibleToUInt16.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToUInt32Infrastructure. For a description of this member, see IConvertibleToUInt32.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToUInt64Infrastructure. For a description of this member, see IConvertibleToUInt64.
Top
Remarks

The Single value type represents a single-precision 32-bit number with values ranging from negative 3.402823e38 to positive 3.402823e38, as well as positive or negative zero, PositiveInfinity, NegativeInfinity, and not a number ( NaN).

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 Formatting Types, Standard Numeric Format Strings, and Custom Numeric Format Strings.

Using Floating-Point Numbers

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:

  • If one of the operands is of an integral type, then that operand is converted to the floating-point type of the other operand.

  • Then, if either of the operands is Double, the other operand is converted to Double, and the operation is performed using at least the range and precision of the Double. For numeric operations, the type of the result is Double.

  • Otherwise, the operation is performed using at least the range and precision of the Single type and, for numeric operations, the type of the result is Single.

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:

  • If the result of a floating-point operation is too small for the destination format, the result of the operation is zero.

  • If the magnitude of the result of a floating-point operation is too large for the destination format, the result of the operation is PositiveInfinity or NegativeInfinity, as appropriate for the sign of the result.

  • If a floating-point operation is invalid, the result of the operation is NaN.

  • If one or both operands of a floating-point operation are NaN, the result of the operation is NaN.

Floating-Point Values and Loss of Precision

Remember that a floating-point number can only approximate a decimal number, and that the precision of a floating-point number determines how accurately that number approximates a decimal number. By default, a Single value contains only 7 decimal digits of precision, although a maximum of 9 digits is maintained internally. The precision of a floating-point number has several consequences:

  • Two floating-point numbers that appear equal for a particular precision might not compare equal because their least significant digits are different.

  • A mathematical or comparison operation that uses a floating-point number might not yield the same result if a decimal number is used because the floating-point number might not exactly approximate the decimal number.

  • A value might not roundtrip if a floating-point number is involved. A value is said to roundtrip if an operation converts an original floating-point number to another form, an inverse operation transforms the converted form back to a floating-point number, and the final floating-point number is equal to the original floating-point number. The roundtrip might fail because one or more least significant digits are lost or changed in a conversion.

Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8
Platforms

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety

All members of this type are thread safe. Members that appear to modify instance state actually return a new instance initialized with the new value. As with any other type, reading and writing to a shared variable that contains an instance of this type must be protected by a lock to guarantee thread safety.