NumberLikeData
Represents one of several standard numeric data types. Components which operate on or yield numeric data of various kinds can use this type to avoid unnecessary casting in input or output parameters.
Methods
Cast
#public static NumberLikeType Cast(object data, out int integer, out double number, out Angle angle, out Complex complex, out BigInteger integerX)
Cast an object to the correct numeric type.
Parameters:
| data (object) | Data to cast. |
| integer (out int) | Output in case data is a 32-bit integer. |
| number (out double) | Output in case data is a 64-bit decimal or a 32-bit integer, or the radian portion of an angle. |
| angle (out Angle) | Output in case data is a 64-bit angle. |
| complex (out Complex) | Output in case data is a 64-bit complex number. |
| integerX (out BigInteger) | Output in case data is a variable-bit integer. |
Returns: The type of data.
CastOrConvert
#public static NumberLikeType CastOrConvert(IEnumerable data, out Array array, out int nullCount, out int nonNumericCount)
Cast or convert a collection of number like data to an array of a single type.
Parameters:
| data (IEnumerable) | Data to convert. |
| array (out Array) | Array of a specific type. |
| nullCount (out int) | Amount of nulls encountered in data. |
| nonNumericCount (out int) | Amount of non-numeric values encountered in data. |
Returns: The most common type of data.
CastOrConvert
#public static NumberLikeType CastOrConvert(object data, out int integer, out double number, out Angle angle, out Complex complex, out BigInteger integerX)
Cast or convert an object to a numeric type if possible.
Parameters:
| data (object) | Data to cast. |
| integer (out int) | Output in case data is a 32-bit integer. |
| number (out double) | Output in case data is a 64-bit decimal. |
| angle (out Angle) | Output in case data is a 64-bit angle. |
| complex (out Complex) | Output in case data is a 64-bit complex number. |
| integerX (out BigInteger) | Output in case data is a variable-bit integer. |
Returns: Numeric type, if any.
Convert
#public static NumberLikeType Convert(object data, out int integer, out double number, out Angle angle, out Complex complex, out BigInteger integerX)
Convert an object to a numeric type if possible. This is a potentially very expensive method to call as it will run through registered type conversions.
Parameters:
| data (object) | Data to cast. |
| integer (out int) | Output in case data is a 32-bit integer. |
| number (out double) | Output in case data is a 64-bit decimal. |
| angle (out Angle) | Output in case data is a 64-bit angle. |
| complex (out Complex) | Output in case data is a 64-bit complex number. |
| integerX (out BigInteger) | Output in case data is a variable-bit integer. |
Returns: Numeric type, if any.
IsNumeric
#Check whether a value is a kind of numeric value. This method does not take into account possible type conversions into numeric values.
Parameters:
| data (object) | Data to check. |
Returns: Type of numeric, or None is the data is null or not a numeric type.
ToComplex
#public static Complex ToComplex(NumberLikeType type, int integer, double number, Angle angle, Complex complex, BigInteger integerX)
Create a complex number based on a pre-existing value and a type.
Parameters:
| type (NumberLikeType) | Argument to use. |
| integer (int) | Integer, only used if type==integer |
| number (double) | Floating point number, only used if type==decimal |
| angle (Angle) | Angle, only used if type==angle |
| complex (Complex) | Complex, returned directly if type==complex |
| integerX (BigInteger) | Big integer, used only if type==bigInteger |
Returns: Complex number which best approximates the implied numeric value.
ToDouble
#Try and convert a value into a double.
UnifyTypes
#Unify the types of two numberlike values. This method uses a standard fallback sequence: Integer -> IntegerX -> Decimal -> Complex. And Angle -> Decimal -> Complex
Parameters:
| a (object) | First value. |
| b (object) | Second value. |
| aʹ (out object) | Unified first value. |
| bʹ (out object) | Unified second value. |
| type (out NumberLikeType) | Unification type. |
Returns: Pair of unified values and the unified type.