Class Converts
Provides various methods related to Convert.
[SuppressMessage("ReSharper", "MergeConditionalExpression")]
[SuppressMessage("ReSharper", "JoinDeclarationAndInitializer")]
public static class Converts
- Inheritance
-
Converts
- Inherited Members
Remarks
Number → text is the NumPy scalar's str() — the text astype('U') writes for the element
(NumSharp.Backends.Strings.NDTextFormat): 1.0 → '1.0', 1e20 → '1e+20', NaN → 'nan', a
float32 or float16 value with its own shortest digits (np.float32(0.1) → '0.1'), a complex value
as '(1+2j)', a bool as 'True' / 'False'. NumSharp's two dtypes without a NumPy analog
follow their documented text rules: a decimal is written as the float64 it converts to, and a
char (NumSharp's 16-bit code unit, a uint16 in every type rule) as its number ('a' →
'97'), as np.array(new[] { 'a' }).astype("U") gives.
Text → number is NumPy's store of a Python str into the dtype (a[0] = '1.5'):
CPython 3.12's int() / float() / complex() grammar (whitespace, underscores between digits,
non-ASCII decimal digits, inf / nan in any case), NumPy's packing check for an integer target, and
NumPy's error texts quoting the str (ParseObject(string, NPTypeCode, byte*)). A bool
target takes the str's truth value (any non-empty str is True — 'False' included — as NumPy 2.x's
str → bool cast and BOOL_setitem give).
Both directions are culture-invariant: NumPy's text has no culture. These replace the .NET forms the class
carried before (double.ToString(CultureInfo.CurrentCulture), int.Parse(s, CurrentCulture)), whose
result depended on the machine's culture (under de-DE "1.5" parsed as 15) and differed from every NumPy
route NumSharp already runs (astype, setitem, np.array, fill).
Fields
DBNull
public static readonly object DBNull
Field Value
Methods
ChangeType(object, NPTypeCode)
Returns an object of the specified type whose value is equivalent to the specified object.
public static object ChangeType(object value, NPTypeCode typeCode)
Parameters
valueobjectAn object that implements the IConvertible interface.
typeCodeNPTypeCodeThe type of object to return.
Returns
- object
An object whose underlying type is
typeCodeand whose value is equivalent tovalue. -or- A null reference (Nothing in Visual Basic), ifvalueis null andtypeCodeis Empty, String, or Object.
Exceptions
- InvalidCastException
This conversion is not supported. -or-
valueis null andtypeCodespecifies a value type. -or-valuedoes not implement the IConvertible interface.- FormatException
valueis not in a format recognized by thetypeCodetype.- OverflowException
valuerepresents a number that is out of the range of thetypeCodetype.- ArgumentException
typeCodeis invalid.
ChangeType(object, NPTypeCode, IFormatProvider)
Returns an object of the specified type whose value is equivalent to the specified object.
public static object ChangeType(object value, NPTypeCode typeCode, IFormatProvider provider)
Parameters
valueobjectAn object that implements the IConvertible interface.
typeCodeNPTypeCodeThe type of object to return.
providerIFormatProvider
Returns
- object
An object whose underlying type is
typeCodeand whose value is equivalent tovalue. -or- A null reference (Nothing in Visual Basic), ifvalueis null andtypeCodeis Empty, String, or Object.
Exceptions
- InvalidCastException
This conversion is not supported. -or-
valueis null andtypeCodespecifies a value type. -or-valuedoes not implement the IConvertible interface.- FormatException
valueis not in a format recognized by thetypeCodetype.- OverflowException
valuerepresents a number that is out of the range of thetypeCodetype.- ArgumentException
typeCodeis invalid.
ChangeType(object, TypeCode)
public static object ChangeType(object value, TypeCode typeCode)
Parameters
Returns
ChangeType(object, TypeCode, IFormatProvider)
public static object ChangeType(object value, TypeCode typeCode, IFormatProvider provider)
Parameters
valueobjecttypeCodeTypeCodeproviderIFormatProvider
Returns
ChangeType<TOut>(object)
Returns an object of the specified type whose value is equivalent to the specified object.
public static TOut ChangeType<TOut>(object value)
Parameters
valueobjectAn object that implements the IConvertible interface.
Returns
- TOut
An object whose underlying type is
typeCodeand whose value is equivalent tovalue. -or- A null reference (Nothing in Visual Basic), ifvalueis null andtypeCodeis Empty, String, or Object.
Type Parameters
TOut
Exceptions
- InvalidCastException
This conversion is not supported. -or-
valueis null andtypeCodespecifies a value type. -or-valuedoes not implement the IConvertible interface.- FormatException
valueis not in a format recognized by thetypeCodetype.- OverflowException
valuerepresents a number that is out of the range of thetypeCodetype.- ArgumentException
typeCodeis invalid.
ChangeType<T>(T, NPTypeCode)
Returns an object of the specified type whose value is equivalent to the specified object.
public static object ChangeType<T>(T value, NPTypeCode typeCode)
Parameters
valueTAn object that implements the IConvertible interface.
typeCodeNPTypeCodeThe type of object to return.
Returns
- object
An object whose underlying type is
typeCodeand whose value is equivalent tovalue. -or- A null reference (Nothing in Visual Basic), ifvalueis null andtypeCodeis Empty, String, or Object.
Type Parameters
T
Exceptions
- InvalidCastException
This conversion is not supported. -or-
valueis null andtypeCodespecifies a value type. -or-valuedoes not implement the IConvertible interface.- FormatException
valueis not in a format recognized by thetypeCodetype.- OverflowException
valuerepresents a number that is out of the range of thetypeCodetype.- ArgumentException
typeCodeis invalid.
ChangeType<TIn, TOut>(TIn)
Returns an object of the specified type whose value is equivalent to the specified object.
public static TOut ChangeType<TIn, TOut>(TIn value)
Parameters
valueTInAn object that implements the IConvertible interface.
Returns
- TOut
An object whose underlying type is
typeCodeand whose value is equivalent tovalue. -or- A null reference (Nothing in Visual Basic), ifvalueis null andtypeCodeis Empty, String, or Object.
Type Parameters
TInTOut
Exceptions
- InvalidCastException
This conversion is not supported. -or-
valueis null andtypeCodespecifies a value type. -or-valuedoes not implement the IConvertible interface.- FormatException
valueis not in a format recognized by thetypeCodetype.- OverflowException
valuerepresents a number that is out of the range of thetypeCodetype.- ArgumentException
typeCodeis invalid.
FindConverter<TIn, TOut>()
Finds the conversion method from Convert based on TIn and TOut.
public static Func<TIn, TOut> FindConverter<TIn, TOut>()
Returns
- Func<TIn, TOut>
Type Parameters
TInThe type that is expected as input and to be converted from
TOutThe type we expect to convert to.
FromBase64CharArray(char[], int, int)
Converts the specified range of a Char array, which encodes binary data as Base64 digits, to the equivalent byte array.
public static byte[] FromBase64CharArray(char[] inArray, int offset, int length)
Parameters
inArraychar[]Chars representing Base64 encoding characters
offsetintA position within the input array.
lengthintNumber of element to convert.
Returns
- byte[]
The array of bytes represented by the specified Base64 encoding characters.
FromBase64String(string)
Converts the specified string, which encodes binary data as Base64 digits, to the equivalent byte array.
public static byte[] FromBase64String(string s)
Parameters
sstringThe string to convert
Returns
- byte[]
The array of bytes represented by the specifed Base64 string.
GetTypeCode(object)
[Pure]
public static TypeCode GetTypeCode(object value)
Parameters
valueobject
Returns
IsDBNull(object)
[Pure]
public static bool IsDBNull(object value)
Parameters
valueobject
Returns
ToBase64CharArray(byte[], int, int, char[], int)
public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut)
Parameters
Returns
ToBase64CharArray(byte[], int, int, char[], int, Base64FormattingOptions)
[ComVisible(false)]
public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut, Base64FormattingOptions options)
Parameters
inArraybyte[]offsetInintlengthintoutArraychar[]offsetOutintoptionsBase64FormattingOptions
Returns
ToBoolean(Char8)
public static bool ToBoolean(Char8 value)
Parameters
valueChar8
Returns
ToBoolean(DateTime64)
public static bool ToBoolean(DateTime64 value)
Parameters
valueDateTime64
Returns
ToBoolean(NDArray)
public static bool ToBoolean(NDArray nd)
Parameters
ndNDArray
Returns
ToBoolean(bool)
public static bool ToBoolean(bool value)
Parameters
valuebool
Returns
ToBoolean(byte)
public static bool ToBoolean(byte value)
Parameters
valuebyte
Returns
ToBoolean(char)
public static bool ToBoolean(char value)
Parameters
valuechar
Returns
ToBoolean(DateTime)
public static bool ToBoolean(DateTime value)
Parameters
valueDateTime
Returns
ToBoolean(decimal)
public static bool ToBoolean(decimal value)
Parameters
valuedecimal
Returns
ToBoolean(double)
public static bool ToBoolean(double value)
Parameters
valuedouble
Returns
ToBoolean(Half)
public static bool ToBoolean(Half value)
Parameters
valueHalf
Returns
ToBoolean(short)
public static bool ToBoolean(short value)
Parameters
valueshort
Returns
ToBoolean(int)
public static bool ToBoolean(int value)
Parameters
valueint
Returns
ToBoolean(long)
public static bool ToBoolean(long value)
Parameters
valuelong
Returns
ToBoolean(Complex)
public static bool ToBoolean(Complex value)
Parameters
valueComplex
Returns
ToBoolean(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to Boolean: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToBoolean(string)),
anything else through its IConvertible.
public static bool ToBoolean(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- bool
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToBoolean(object, IFormatProvider)
public static bool ToBoolean(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToBoolean(sbyte)
public static bool ToBoolean(sbyte value)
Parameters
valuesbyte
Returns
ToBoolean(float)
public static bool ToBoolean(float value)
Parameters
valuefloat
Returns
ToBoolean(string)
Converts a Python str to a bool as NumPy does (np.array([text]).astype(bool), BOOL_setitem):
the str's truth value, True for any non-empty text — "False" and "0" included.
public static bool ToBoolean(string value)
Parameters
Returns
- bool
The bool value.
ToBoolean(string, IFormatProvider)
ToBoolean(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static bool ToBoolean(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives false.
providerIFormatProviderIgnored.
Returns
- bool
The bool value.
ToBoolean(TimeSpan)
public static bool ToBoolean(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToBoolean(ushort)
public static bool ToBoolean(ushort value)
Parameters
valueushort
Returns
ToBoolean(uint)
public static bool ToBoolean(uint value)
Parameters
valueuint
Returns
ToBoolean(ulong)
public static bool ToBoolean(ulong value)
Parameters
valueulong
Returns
ToByte(Char8)
public static byte ToByte(Char8 value)
Parameters
valueChar8
Returns
ToByte(DateTime64)
public static byte ToByte(DateTime64 value)
Parameters
valueDateTime64
Returns
ToByte(NDArray)
public static byte ToByte(NDArray nd)
Parameters
ndNDArray
Returns
ToByte(bool)
public static byte ToByte(bool value)
Parameters
valuebool
Returns
ToByte(byte)
public static byte ToByte(byte value)
Parameters
valuebyte
Returns
ToByte(char)
public static byte ToByte(char value)
Parameters
valuechar
Returns
ToByte(DateTime)
public static byte ToByte(DateTime value)
Parameters
valueDateTime
Returns
ToByte(decimal)
public static byte ToByte(decimal value)
Parameters
valuedecimal
Returns
ToByte(double)
public static byte ToByte(double value)
Parameters
valuedouble
Returns
ToByte(Half)
public static byte ToByte(Half value)
Parameters
valueHalf
Returns
ToByte(short)
public static byte ToByte(short value)
Parameters
valueshort
Returns
ToByte(int)
public static byte ToByte(int value)
Parameters
valueint
Returns
ToByte(long)
public static byte ToByte(long value)
Parameters
valuelong
Returns
ToByte(Complex)
public static byte ToByte(Complex value)
Parameters
valueComplex
Returns
ToByte(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to Byte: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToByte(string)),
anything else through its IConvertible.
public static byte ToByte(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- byte
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToByte(object, IFormatProvider)
public static byte ToByte(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToByte(sbyte)
public static byte ToByte(sbyte value)
Parameters
valuesbyte
Returns
ToByte(float)
public static byte ToByte(float value)
Parameters
valuefloat
Returns
ToByte(string)
Converts a Python str to uint8 as NumPy stores it into a uint8 array (a[0] = text):
CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.
public static byte ToByte(string value)
Parameters
Returns
- byte
The uint8 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside uint8 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToByte(string, IFormatProvider)
ToByte(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static byte ToByte(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives 0.
providerIFormatProviderIgnored.
Returns
- byte
The uint8 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside uint8 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToByte(TimeSpan)
public static byte ToByte(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToByte(ushort)
public static byte ToByte(ushort value)
Parameters
valueushort
Returns
ToByte(uint)
public static byte ToByte(uint value)
Parameters
valueuint
Returns
ToByte(ulong)
public static byte ToByte(ulong value)
Parameters
valueulong
Returns
ToByteArray(Char8[])
Converts a Char8[] to byte[].
public static byte[] ToByteArray(Char8[] src)
Parameters
srcChar8[]
Returns
- byte[]
ToChar(Char8)
public static char ToChar(Char8 value)
Parameters
valueChar8
Returns
ToChar(DateTime64)
public static char ToChar(DateTime64 value)
Parameters
valueDateTime64
Returns
ToChar(NDArray)
public static char ToChar(NDArray nd)
Parameters
ndNDArray
Returns
ToChar(bool)
public static char ToChar(bool value)
Parameters
valuebool
Returns
ToChar(byte)
public static char ToChar(byte value)
Parameters
valuebyte
Returns
ToChar(char)
public static char ToChar(char value)
Parameters
valuechar
Returns
ToChar(DateTime)
public static char ToChar(DateTime value)
Parameters
valueDateTime
Returns
ToChar(decimal)
public static char ToChar(decimal value)
Parameters
valuedecimal
Returns
ToChar(double)
public static char ToChar(double value)
Parameters
valuedouble
Returns
ToChar(Half)
public static char ToChar(Half value)
Parameters
valueHalf
Returns
ToChar(short)
public static char ToChar(short value)
Parameters
valueshort
Returns
ToChar(int)
public static char ToChar(int value)
Parameters
valueint
Returns
ToChar(long)
public static char ToChar(long value)
Parameters
valuelong
Returns
ToChar(Complex)
public static char ToChar(Complex value)
Parameters
valueComplex
Returns
ToChar(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to Char: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToChar(string)),
anything else through its IConvertible.
public static char ToChar(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- char
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToChar(object, IFormatProvider)
public static char ToChar(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToChar(sbyte)
public static char ToChar(sbyte value)
Parameters
valuesbyte
Returns
ToChar(float)
public static char ToChar(float value)
Parameters
valuefloat
Returns
ToChar(string)
Converts a Python str to char as NumPy stores it into a char array (a[0] = text):
CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.
NumSharp's char dtype is a 16-bit code unit that crosses to text as its uint16 number, so the text is
a number ("97" → 'a'), as astype of a U array to char reads it.
public static char ToChar(string value)
Parameters
Returns
- char
The char value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside char (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToChar(string, IFormatProvider)
ToChar(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static char ToChar(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives the NUL char.
providerIFormatProviderIgnored.
Returns
- char
The char value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside char (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToChar(TimeSpan)
public static char ToChar(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToChar(ushort)
public static char ToChar(ushort value)
Parameters
valueushort
Returns
ToChar(uint)
public static char ToChar(uint value)
Parameters
valueuint
Returns
ToChar(ulong)
public static char ToChar(ulong value)
Parameters
valueulong
Returns
ToChar8(Char8)
public static Char8 ToChar8(Char8 value)
Parameters
valueChar8
Returns
ToChar8(bool)
public static Char8 ToChar8(bool value)
Parameters
valuebool
Returns
ToChar8(byte)
public static Char8 ToChar8(byte value)
Parameters
valuebyte
Returns
ToChar8(char)
public static Char8 ToChar8(char value)
Parameters
valuechar
Returns
ToChar8(decimal)
public static Char8 ToChar8(decimal value)
Parameters
valuedecimal
Returns
ToChar8(double)
public static Char8 ToChar8(double value)
Parameters
valuedouble
Returns
ToChar8(short)
public static Char8 ToChar8(short value)
Parameters
valueshort
Returns
ToChar8(int)
public static Char8 ToChar8(int value)
Parameters
valueint
Returns
ToChar8(long)
public static Char8 ToChar8(long value)
Parameters
valuelong
Returns
ToChar8(object)
Converts any IConvertible-supporting value to Char8. Dispatches on GetTypeCode().
public static Char8 ToChar8(object value)
Parameters
valueobject
Returns
ToChar8(object, IFormatProvider)
public static Char8 ToChar8(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToChar8(sbyte)
public static Char8 ToChar8(sbyte value)
Parameters
valuesbyte
Returns
ToChar8(float)
public static Char8 ToChar8(float value)
Parameters
valuefloat
Returns
ToChar8(string)
Parses a one-character string as Char8 (Latin-1 decoded). Throws on empty, multi-char, or non-Latin-1.
public static Char8 ToChar8(string value)
Parameters
valuestring
Returns
ToChar8(ushort)
public static Char8 ToChar8(ushort value)
Parameters
valueushort
Returns
ToChar8(uint)
public static Char8 ToChar8(uint value)
Parameters
valueuint
Returns
ToChar8(ulong)
public static Char8 ToChar8(ulong value)
Parameters
valueulong
Returns
ToChar8Array(byte[])
Converts a byte[] to Char8[] (zero-copy reinterpret would require MemoryMarshal; this one copies).
public static Char8[] ToChar8Array(byte[] src)
Parameters
srcbyte[]
Returns
- Char8[]
ToChar8ArrayFromDouble(double[])
public static Char8[] ToChar8ArrayFromDouble(double[] src)
Parameters
srcdouble[]
Returns
- Char8[]
ToChar8ArrayFromInt32(int[])
public static Char8[] ToChar8ArrayFromInt32(int[] src)
Parameters
srcint[]
Returns
- Char8[]
ToChar8<T>(T)
Converts any NumSharp-supported primitive value to Char8. Dispatches on NPTypeCode.
public static Char8 ToChar8<T>(T value) where T : struct
Parameters
valueT
Returns
Type Parameters
T
ToComplex(DateTime64)
public static Complex ToComplex(DateTime64 value)
Parameters
valueDateTime64
Returns
ToComplex(bool)
public static Complex ToComplex(bool value)
Parameters
valuebool
Returns
ToComplex(byte)
public static Complex ToComplex(byte value)
Parameters
valuebyte
Returns
ToComplex(char)
public static Complex ToComplex(char value)
Parameters
valuechar
Returns
ToComplex(DateTime)
public static Complex ToComplex(DateTime value)
Parameters
valueDateTime
Returns
ToComplex(decimal)
public static Complex ToComplex(decimal value)
Parameters
valuedecimal
Returns
ToComplex(double)
public static Complex ToComplex(double value)
Parameters
valuedouble
Returns
ToComplex(Half)
float16 → complex128: the real part is the float16 converted exactly to float64 with NumPy's NaN rule (ToDouble(Half) — a signalling NaN stays signalling); the imaginary part is +0.
public static Complex ToComplex(Half value)
Parameters
valueHalfThe value to convert.
Returns
- Complex
The complex value
value+ 0j.
ToComplex(short)
public static Complex ToComplex(short value)
Parameters
valueshort
Returns
ToComplex(int)
public static Complex ToComplex(int value)
Parameters
valueint
Returns
ToComplex(long)
public static Complex ToComplex(long value)
Parameters
valuelong
Returns
ToComplex(Complex)
public static Complex ToComplex(Complex value)
Parameters
valueComplex
Returns
ToComplex(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to Complex: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToComplex(string)),
anything else through its IConvertible.
public static Complex ToComplex(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- Complex
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToComplex(object, IFormatProvider)
public static Complex ToComplex(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToComplex(sbyte)
public static Complex ToComplex(sbyte value)
Parameters
valuesbyte
Returns
ToComplex(float)
public static Complex ToComplex(float value)
Parameters
valuefloat
Returns
ToComplex(string)
Converts a Python str to complex128 as NumPy stores it into a complex128 array (a[0] = text):
CPython's complex() grammar ("1+2j", "(1+2j)", "2j", "inf", whitespace around), culture-invariant.
public static Complex ToComplex(string value)
Parameters
valuestringThe text; null gives zero (C#'s "no value").
Returns
- Complex
The complex128 value.
Exceptions
- ValueError
The text is not a complex literal (CPython's
complex() arg is a malformed string).
ToComplex(string, IFormatProvider)
ToComplex(string): NumPy's text has no culture, so provider is ignored.
public static Complex ToComplex(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives zero.
providerIFormatProviderIgnored.
Returns
- Complex
The complex128 value.
Exceptions
- ValueError
The text is not a complex literal.
ToComplex(TimeSpan)
public static Complex ToComplex(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToComplex(ushort)
public static Complex ToComplex(ushort value)
Parameters
valueushort
Returns
ToComplex(uint)
public static Complex ToComplex(uint value)
Parameters
valueuint
Returns
ToComplex(ulong)
uint64 → complex128: the real part is rounded ONCE to nearest-even (ToDouble(ulong) — not .NET 8's double-rounding conversion); the imaginary part is +0.
public static Complex ToComplex(ulong value)
Parameters
valueulongThe value to convert.
Returns
- Complex
The complex value nearest
value+ 0j.
ToDateTime(DateTime64)
public static DateTime ToDateTime(DateTime64 value)
Parameters
valueDateTime64
Returns
ToDateTime(bool)
public static DateTime ToDateTime(bool value)
Parameters
valuebool
Returns
ToDateTime(byte)
public static DateTime ToDateTime(byte value)
Parameters
valuebyte
Returns
ToDateTime(char)
public static DateTime ToDateTime(char value)
Parameters
valuechar
Returns
ToDateTime(DateTime)
public static DateTime ToDateTime(DateTime value)
Parameters
valueDateTime
Returns
ToDateTime(decimal)
public static DateTime ToDateTime(decimal value)
Parameters
valuedecimal
Returns
ToDateTime(double)
public static DateTime ToDateTime(double value)
Parameters
valuedouble
Returns
ToDateTime(Half)
public static DateTime ToDateTime(Half value)
Parameters
valueHalf
Returns
ToDateTime(short)
public static DateTime ToDateTime(short value)
Parameters
valueshort
Returns
ToDateTime(int)
public static DateTime ToDateTime(int value)
Parameters
valueint
Returns
ToDateTime(long)
public static DateTime ToDateTime(long value)
Parameters
valuelong
Returns
ToDateTime(Complex)
public static DateTime ToDateTime(Complex value)
Parameters
valueComplex
Returns
ToDateTime(object)
public static DateTime ToDateTime(object value)
Parameters
valueobject
Returns
ToDateTime(object, IFormatProvider)
public static DateTime ToDateTime(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToDateTime(sbyte)
public static DateTime ToDateTime(sbyte value)
Parameters
valuesbyte
Returns
ToDateTime(float)
public static DateTime ToDateTime(float value)
Parameters
valuefloat
Returns
ToDateTime(string)
public static DateTime ToDateTime(string value)
Parameters
valuestring
Returns
ToDateTime(string, IFormatProvider)
public static DateTime ToDateTime(string value, IFormatProvider provider)
Parameters
valuestringproviderIFormatProvider
Returns
ToDateTime(TimeSpan)
public static DateTime ToDateTime(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToDateTime(ushort)
public static DateTime ToDateTime(ushort value)
Parameters
valueushort
Returns
ToDateTime(uint)
public static DateTime ToDateTime(uint value)
Parameters
valueuint
Returns
ToDateTime(ulong)
public static DateTime ToDateTime(ulong value)
Parameters
valueulong
Returns
ToDateTime64(DateTime64)
public static DateTime64 ToDateTime64(DateTime64 value)
Parameters
valueDateTime64
Returns
ToDateTime64(bool)
public static DateTime64 ToDateTime64(bool value)
Parameters
valuebool
Returns
ToDateTime64(byte)
public static DateTime64 ToDateTime64(byte value)
Parameters
valuebyte
Returns
ToDateTime64(char)
public static DateTime64 ToDateTime64(char value)
Parameters
valuechar
Returns
ToDateTime64(DateTime)
public static DateTime64 ToDateTime64(DateTime value)
Parameters
valueDateTime
Returns
ToDateTime64(DateTimeOffset)
public static DateTime64 ToDateTime64(DateTimeOffset value)
Parameters
valueDateTimeOffset
Returns
ToDateTime64(decimal)
public static DateTime64 ToDateTime64(decimal value)
Parameters
valuedecimal
Returns
ToDateTime64(double)
public static DateTime64 ToDateTime64(double value)
Parameters
valuedouble
Returns
ToDateTime64(Half)
public static DateTime64 ToDateTime64(Half value)
Parameters
valueHalf
Returns
ToDateTime64(short)
public static DateTime64 ToDateTime64(short value)
Parameters
valueshort
Returns
ToDateTime64(int)
public static DateTime64 ToDateTime64(int value)
Parameters
valueint
Returns
ToDateTime64(long)
public static DateTime64 ToDateTime64(long value)
Parameters
valuelong
Returns
ToDateTime64(Complex)
public static DateTime64 ToDateTime64(Complex value)
Parameters
valueComplex
Returns
ToDateTime64(object)
public static DateTime64 ToDateTime64(object value)
Parameters
valueobject
Returns
ToDateTime64(object, IFormatProvider)
public static DateTime64 ToDateTime64(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToDateTime64(sbyte)
public static DateTime64 ToDateTime64(sbyte value)
Parameters
valuesbyte
Returns
ToDateTime64(float)
public static DateTime64 ToDateTime64(float value)
Parameters
valuefloat
Returns
ToDateTime64(string)
Parses a datetime text into a DateTime64, culture-invariant: NumPy's datetime64 text is ISO-8601 and has no culture.
public static DateTime64 ToDateTime64(string value)
Parameters
valuestringThe text: an ISO-8601 date / time (ToString()'s output), or
"NaT".
Returns
- DateTime64
The value; NaT for null, the empty string or
"NaT"(NumPy'snp.datetime64('')is NaT too).
Remarks
This read the text in the CURRENT culture before, so the same text gave another date on another machine
("01/02/2020" is January 2 under en-US and February 1 under de-DE), unlike every other text → number
conversion of Converts. A caller that wants a culture passes it to
ToDateTime64(string, IFormatProvider).
Exceptions
- FormatException
The text is not a date / time the invariant culture reads.
ToDateTime64(string, IFormatProvider)
public static DateTime64 ToDateTime64(string value, IFormatProvider provider)
Parameters
valuestringproviderIFormatProvider
Returns
ToDateTime64(TimeSpan)
public static DateTime64 ToDateTime64(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToDateTime64(ushort)
public static DateTime64 ToDateTime64(ushort value)
Parameters
valueushort
Returns
ToDateTime64(uint)
public static DateTime64 ToDateTime64(uint value)
Parameters
valueuint
Returns
ToDateTime64(ulong)
public static DateTime64 ToDateTime64(ulong value)
Parameters
valueulong
Returns
ToDateTimeOffset(DateTime64)
public static DateTimeOffset ToDateTimeOffset(DateTime64 value)
Parameters
valueDateTime64
Returns
ToDecimal(Char8)
public static decimal ToDecimal(Char8 value)
Parameters
valueChar8
Returns
ToDecimal(DateTime64)
public static decimal ToDecimal(DateTime64 value)
Parameters
valueDateTime64
Returns
ToDecimal(NDArray)
public static decimal ToDecimal(NDArray nd)
Parameters
ndNDArray
Returns
ToDecimal(bool)
public static decimal ToDecimal(bool value)
Parameters
valuebool
Returns
ToDecimal(byte)
public static decimal ToDecimal(byte value)
Parameters
valuebyte
Returns
ToDecimal(char)
public static decimal ToDecimal(char value)
Parameters
valuechar
Returns
ToDecimal(DateTime)
public static decimal ToDecimal(DateTime value)
Parameters
valueDateTime
Returns
ToDecimal(decimal)
public static decimal ToDecimal(decimal value)
Parameters
valuedecimal
Returns
ToDecimal(double)
public static decimal ToDecimal(double value)
Parameters
valuedouble
Returns
ToDecimal(Half)
public static decimal ToDecimal(Half value)
Parameters
valueHalf
Returns
ToDecimal(short)
public static decimal ToDecimal(short value)
Parameters
valueshort
Returns
ToDecimal(int)
public static decimal ToDecimal(int value)
Parameters
valueint
Returns
ToDecimal(long)
public static decimal ToDecimal(long value)
Parameters
valuelong
Returns
ToDecimal(Complex)
public static decimal ToDecimal(Complex value)
Parameters
valueComplex
Returns
ToDecimal(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to Decimal: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToDecimal(string)),
anything else through its IConvertible.
public static decimal ToDecimal(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- decimal
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToDecimal(object, IFormatProvider)
public static decimal ToDecimal(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToDecimal(sbyte)
public static decimal ToDecimal(sbyte value)
Parameters
valuesbyte
Returns
ToDecimal(float)
public static decimal ToDecimal(float value)
Parameters
valuefloat
Returns
ToDecimal(string)
Converts a Python str to decimal as NumPy stores it into a decimal array (a[0] = text):
CPython's float() grammar (whitespace, underscores between digits, inf / nan in any case), culture-invariant.
NumSharp's decimal (no NumPy analog) parses as a float64 and converts like the float64 → decimal cast.
public static decimal ToDecimal(string value)
Parameters
Returns
- decimal
The decimal value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').
ToDecimal(string, IFormatProvider)
ToDecimal(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static decimal ToDecimal(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives 0m.
providerIFormatProviderIgnored.
Returns
- decimal
The decimal value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').
ToDecimal(TimeSpan)
public static decimal ToDecimal(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToDecimal(ushort)
public static decimal ToDecimal(ushort value)
Parameters
valueushort
Returns
ToDecimal(uint)
public static decimal ToDecimal(uint value)
Parameters
valueuint
Returns
ToDecimal(ulong)
public static decimal ToDecimal(ulong value)
Parameters
valueulong
Returns
ToDouble(Char8)
public static double ToDouble(Char8 value)
Parameters
valueChar8
Returns
ToDouble(DateTime64)
public static double ToDouble(DateTime64 value)
Parameters
valueDateTime64
Returns
ToDouble(NDArray)
public static double ToDouble(NDArray nd)
Parameters
ndNDArray
Returns
ToDouble(bool)
public static double ToDouble(bool value)
Parameters
valuebool
Returns
ToDouble(byte)
public static double ToDouble(byte value)
Parameters
valuebyte
Returns
ToDouble(char)
public static double ToDouble(char value)
Parameters
valuechar
Returns
ToDouble(DateTime)
public static double ToDouble(DateTime value)
Parameters
valueDateTime
Returns
ToDouble(decimal)
public static double ToDouble(decimal value)
Parameters
valuedecimal
Returns
ToDouble(double)
public static double ToDouble(double value)
Parameters
valuedouble
Returns
ToDouble(Half)
float16 → float64, exact, with NumPy's NaN rule (npy_halfbits_to_doublebits — NumPy converts
directly, not through float32): a NaN keeps its sign and payload and a SIGNALLING NaN stays signalling —
the BCL cast sets the quiet bit.
public static double ToDouble(Half value)
Parameters
valueHalfThe value to convert.
Returns
- double
The same value as float64 (every float16 is exactly representable).
ToDouble(short)
public static double ToDouble(short value)
Parameters
valueshort
Returns
ToDouble(int)
public static double ToDouble(int value)
Parameters
valueint
Returns
ToDouble(long)
public static double ToDouble(long value)
Parameters
valuelong
Returns
ToDouble(Complex)
public static double ToDouble(Complex value)
Parameters
valueComplex
Returns
ToDouble(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to Double: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToDouble(string)),
anything else through its IConvertible.
public static double ToDouble(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- double
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToDouble(object, IFormatProvider)
public static double ToDouble(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToDouble(sbyte)
public static double ToDouble(sbyte value)
Parameters
valuesbyte
Returns
ToDouble(float)
public static double ToDouble(float value)
Parameters
valuefloat
Returns
ToDouble(string)
Converts a Python str to float64 as NumPy stores it into a float64 array (a[0] = text):
CPython's float() grammar (whitespace, underscores between digits, inf / nan in any case), culture-invariant.
public static double ToDouble(string value)
Parameters
Returns
- double
The float64 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').
ToDouble(string, IFormatProvider)
ToDouble(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static double ToDouble(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives 0.
providerIFormatProviderIgnored.
Returns
- double
The float64 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').
ToDouble(TimeSpan)
public static double ToDouble(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToDouble(ushort)
public static double ToDouble(ushort value)
Parameters
valueushort
Returns
ToDouble(uint)
public static double ToDouble(uint value)
Parameters
valueuint
Returns
ToDouble(ulong)
uint64 → float64, rounded ONCE to nearest-even as NumPy's C cast does — not .NET 8's conversion, which from 2⁶³ on converts as signed and adds 2⁶⁴, rounding twice (2⁶³ + 1025 → 2⁶³ instead of 2⁶³ + 2048).
public static double ToDouble(ulong value)
Parameters
valueulongThe value to convert.
Returns
- double
The float64 nearest
value, ties to even.
ToDoubleArray(Char8[])
public static double[] ToDoubleArray(Char8[] src)
Parameters
srcChar8[]
Returns
- double[]
ToHalf(DateTime64)
public static Half ToHalf(DateTime64 value)
Parameters
valueDateTime64
Returns
ToHalf(bool)
public static Half ToHalf(bool value)
Parameters
valuebool
Returns
ToHalf(byte)
public static Half ToHalf(byte value)
Parameters
valuebyte
Returns
ToHalf(char)
public static Half ToHalf(char value)
Parameters
valuechar
Returns
ToHalf(DateTime)
public static Half ToHalf(DateTime value)
Parameters
valueDateTime
Returns
ToHalf(decimal)
public static Half ToHalf(decimal value)
Parameters
valuedecimal
Returns
ToHalf(double)
float64 → float16, rounded ONCE to nearest-even, with NumPy's NaN rule (npy_doublebits_to_halfbits):
a NaN keeps its sign and the top 10 payload bits, a SIGNALLING NaN stays signalling, and one whose kept
bits are all zero becomes 0x7C01 — the BCL cast sets the quiet bit (0x7E00 for the latter).
public static Half ToHalf(double value)
Parameters
valuedoubleThe value to convert.
Returns
- Half
The float16 nearest
value(±inf beyond the float16 range).
ToHalf(Half)
public static Half ToHalf(Half value)
Parameters
valueHalf
Returns
ToHalf(short)
public static Half ToHalf(short value)
Parameters
valueshort
Returns
ToHalf(int)
public static Half ToHalf(int value)
Parameters
valueint
Returns
ToHalf(long)
public static Half ToHalf(long value)
Parameters
valuelong
Returns
ToHalf(Complex)
complex128 → float16: NumPy takes the real part and converts it as float64 → float16 (ToHalf(double), so a signalling NaN stays signalling).
public static Half ToHalf(Complex value)
Parameters
valueComplexThe value to convert.
Returns
- Half
The float16 nearest the real part.
ToHalf(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to Half: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToHalf(string)),
anything else through its IConvertible.
public static Half ToHalf(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- Half
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToHalf(object, IFormatProvider)
public static Half ToHalf(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToHalf(sbyte)
public static Half ToHalf(sbyte value)
Parameters
valuesbyte
Returns
ToHalf(float)
float32 → float16, rounded to nearest-even, with NumPy's NaN rule (npy_floatbits_to_halfbits): a
NaN keeps its sign and the top 10 payload bits, a SIGNALLING NaN stays signalling, and one whose kept
bits are all zero becomes 0x7C01 — the BCL cast sets the quiet bit (0x7E00 for the latter).
public static Half ToHalf(float value)
Parameters
valuefloatThe value to convert.
Returns
- Half
The float16 nearest
value(±inf beyond the float16 range).
ToHalf(string)
Converts a Python str to float16 as NumPy stores it into a float16 array (a[0] = text):
CPython's float() grammar (whitespace, underscores between digits, inf / nan in any case), culture-invariant.
The parsed float64 is rounded once more into float16, as NumPy's store rounds it.
public static Half ToHalf(string value)
Parameters
Returns
- Half
The float16 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').
ToHalf(string, IFormatProvider)
ToHalf(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static Half ToHalf(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives default.
providerIFormatProviderIgnored.
Returns
- Half
The float16 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').
ToHalf(TimeSpan)
public static Half ToHalf(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToHalf(ushort)
public static Half ToHalf(ushort value)
Parameters
valueushort
Returns
ToHalf(uint)
public static Half ToHalf(uint value)
Parameters
valueuint
Returns
ToHalf(ulong)
public static Half ToHalf(ulong value)
Parameters
valueulong
Returns
ToInt16(Char8)
public static short ToInt16(Char8 value)
Parameters
valueChar8
Returns
ToInt16(DateTime64)
public static short ToInt16(DateTime64 value)
Parameters
valueDateTime64
Returns
ToInt16(NDArray)
public static short ToInt16(NDArray nd)
Parameters
ndNDArray
Returns
ToInt16(bool)
public static short ToInt16(bool value)
Parameters
valuebool
Returns
ToInt16(byte)
public static short ToInt16(byte value)
Parameters
valuebyte
Returns
ToInt16(char)
public static short ToInt16(char value)
Parameters
valuechar
Returns
ToInt16(DateTime)
public static short ToInt16(DateTime value)
Parameters
valueDateTime
Returns
ToInt16(decimal)
public static short ToInt16(decimal value)
Parameters
valuedecimal
Returns
ToInt16(double)
public static short ToInt16(double value)
Parameters
valuedouble
Returns
ToInt16(Half)
public static short ToInt16(Half value)
Parameters
valueHalf
Returns
ToInt16(short)
public static short ToInt16(short value)
Parameters
valueshort
Returns
ToInt16(int)
public static short ToInt16(int value)
Parameters
valueint
Returns
ToInt16(long)
public static short ToInt16(long value)
Parameters
valuelong
Returns
ToInt16(Complex)
public static short ToInt16(Complex value)
Parameters
valueComplex
Returns
ToInt16(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to Int16: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToInt16(string)),
anything else through its IConvertible.
public static short ToInt16(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- short
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToInt16(object, IFormatProvider)
public static short ToInt16(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToInt16(sbyte)
public static short ToInt16(sbyte value)
Parameters
valuesbyte
Returns
ToInt16(float)
public static short ToInt16(float value)
Parameters
valuefloat
Returns
ToInt16(string)
Converts a Python str to int16 as NumPy stores it into a int16 array (a[0] = text):
CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.
public static short ToInt16(string value)
Parameters
Returns
- short
The int16 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside int16 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToInt16(string, IFormatProvider)
ToInt16(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static short ToInt16(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives 0.
providerIFormatProviderIgnored.
Returns
- short
The int16 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside int16 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToInt16(TimeSpan)
public static short ToInt16(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToInt16(ushort)
public static short ToInt16(ushort value)
Parameters
valueushort
Returns
ToInt16(uint)
public static short ToInt16(uint value)
Parameters
valueuint
Returns
ToInt16(ulong)
public static short ToInt16(ulong value)
Parameters
valueulong
Returns
ToInt32(Char8)
public static int ToInt32(Char8 value)
Parameters
valueChar8
Returns
ToInt32(DateTime64)
public static int ToInt32(DateTime64 value)
Parameters
valueDateTime64
Returns
ToInt32(NDArray)
public static int ToInt32(NDArray nd)
Parameters
ndNDArray
Returns
ToInt32(bool)
public static int ToInt32(bool value)
Parameters
valuebool
Returns
ToInt32(byte)
public static int ToInt32(byte value)
Parameters
valuebyte
Returns
ToInt32(char)
public static int ToInt32(char value)
Parameters
valuechar
Returns
ToInt32(DateTime)
public static int ToInt32(DateTime value)
Parameters
valueDateTime
Returns
ToInt32(decimal)
public static int ToInt32(decimal value)
Parameters
valuedecimal
Returns
ToInt32(double)
NumPy's float64 → int32 cast: truncation toward zero, and int32.MinValue for NaN, ±Inf and every value whose truncation leaves int32's range. Also the per-element body of the float → {int8, uint8, int16, uint16, char} casts (ToInt16(double) and its siblings narrow its result), which every cast kernel calls on a host without the x86 vector cast (arm64; Mono on Android, iOS and WebAssembly).
public static int ToInt32(double value)
Parameters
valuedoubleThe value to convert.
Returns
- int
The truncated value, or int32.MinValue when it has none in int32.
Remarks
One range test on the untruncated value decides every case: each double in the open interval (-2^31 - 1, 2^31) truncates into int32's range (2147483647.4 → 2147483647, -2147483648.9 → int.MinValue), every other value is out, and NaN fails both comparisons. Both bounds are exact doubles, and the cast inside the range truncates the same way on every runtime. The result equals the truncate-then-test form this replaced for all 2^32 float32 inputs and the boundary doubles; that form called Truncate(double), which Mono compiles to a call: ~15 ns an element on an arm64 phone, 5x the cost of a plain C# cast loop there.
ToInt32(Half)
public static int ToInt32(Half value)
Parameters
valueHalf
Returns
ToInt32(short)
public static int ToInt32(short value)
Parameters
valueshort
Returns
ToInt32(int)
public static int ToInt32(int value)
Parameters
valueint
Returns
ToInt32(long)
public static int ToInt32(long value)
Parameters
valuelong
Returns
ToInt32(Complex)
public static int ToInt32(Complex value)
Parameters
valueComplex
Returns
ToInt32(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to Int32: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToInt32(string)),
anything else through its IConvertible.
public static int ToInt32(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- int
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToInt32(object, IFormatProvider)
public static int ToInt32(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToInt32(sbyte)
public static int ToInt32(sbyte value)
Parameters
valuesbyte
Returns
ToInt32(float)
public static int ToInt32(float value)
Parameters
valuefloat
Returns
ToInt32(string)
Converts a Python str to int32 as NumPy stores it into a int32 array (a[0] = text):
CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.
public static int ToInt32(string value)
Parameters
Returns
- int
The int32 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside int32 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToInt32(string, IFormatProvider)
ToInt32(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static int ToInt32(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives 0.
providerIFormatProviderIgnored.
Returns
- int
The int32 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside int32 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToInt32(TimeSpan)
public static int ToInt32(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToInt32(ushort)
public static int ToInt32(ushort value)
Parameters
valueushort
Returns
ToInt32(uint)
public static int ToInt32(uint value)
Parameters
valueuint
Returns
ToInt32(ulong)
public static int ToInt32(ulong value)
Parameters
valueulong
Returns
ToInt32Array(Char8[])
public static int[] ToInt32Array(Char8[] src)
Parameters
srcChar8[]
Returns
- int[]
ToInt64(Char8)
public static long ToInt64(Char8 value)
Parameters
valueChar8
Returns
ToInt64(DateTime64)
public static long ToInt64(DateTime64 value)
Parameters
valueDateTime64
Returns
ToInt64(NDArray)
public static long ToInt64(NDArray nd)
Parameters
ndNDArray
Returns
ToInt64(bool)
public static long ToInt64(bool value)
Parameters
valuebool
Returns
ToInt64(byte)
public static long ToInt64(byte value)
Parameters
valuebyte
Returns
ToInt64(char)
public static long ToInt64(char value)
Parameters
valuechar
Returns
ToInt64(DateTime)
public static long ToInt64(DateTime value)
Parameters
valueDateTime
Returns
ToInt64(decimal)
public static long ToInt64(decimal value)
Parameters
valuedecimal
Returns
ToInt64(double)
public static long ToInt64(double value)
Parameters
valuedouble
Returns
ToInt64(Half)
public static long ToInt64(Half value)
Parameters
valueHalf
Returns
ToInt64(short)
public static long ToInt64(short value)
Parameters
valueshort
Returns
ToInt64(int)
public static long ToInt64(int value)
Parameters
valueint
Returns
ToInt64(long)
public static long ToInt64(long value)
Parameters
valuelong
Returns
ToInt64(Complex)
public static long ToInt64(Complex value)
Parameters
valueComplex
Returns
ToInt64(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to Int64: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToInt64(string)),
anything else through its IConvertible.
public static long ToInt64(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- long
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToInt64(object, IFormatProvider)
public static long ToInt64(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToInt64(sbyte)
public static long ToInt64(sbyte value)
Parameters
valuesbyte
Returns
ToInt64(float)
public static long ToInt64(float value)
Parameters
valuefloat
Returns
ToInt64(string)
Converts a Python str to int64 as NumPy stores it into a int64 array (a[0] = text):
CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.
public static long ToInt64(string value)
Parameters
Returns
- long
The int64 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside int64 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToInt64(string, IFormatProvider)
ToInt64(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static long ToInt64(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives 0.
providerIFormatProviderIgnored.
Returns
- long
The int64 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside int64 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToInt64(TimeSpan)
public static long ToInt64(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToInt64(ushort)
public static long ToInt64(ushort value)
Parameters
valueushort
Returns
ToInt64(uint)
public static long ToInt64(uint value)
Parameters
valueuint
Returns
ToInt64(ulong)
public static long ToInt64(ulong value)
Parameters
valueulong
Returns
ToObject(Char8, NPTypeCode)
Converts a Char8 to a NumSharp-supported primitive by target type code.
public static object ToObject(Char8 value, NPTypeCode typeCode)
Parameters
valueChar8typeCodeNPTypeCode
Returns
ToSByte(Char8)
public static sbyte ToSByte(Char8 value)
Parameters
valueChar8
Returns
ToSByte(DateTime64)
public static sbyte ToSByte(DateTime64 value)
Parameters
valueDateTime64
Returns
ToSByte(bool)
public static sbyte ToSByte(bool value)
Parameters
valuebool
Returns
ToSByte(byte)
public static sbyte ToSByte(byte value)
Parameters
valuebyte
Returns
ToSByte(char)
public static sbyte ToSByte(char value)
Parameters
valuechar
Returns
ToSByte(DateTime)
public static sbyte ToSByte(DateTime value)
Parameters
valueDateTime
Returns
ToSByte(decimal)
public static sbyte ToSByte(decimal value)
Parameters
valuedecimal
Returns
ToSByte(double)
public static sbyte ToSByte(double value)
Parameters
valuedouble
Returns
ToSByte(Half)
public static sbyte ToSByte(Half value)
Parameters
valueHalf
Returns
ToSByte(short)
public static sbyte ToSByte(short value)
Parameters
valueshort
Returns
ToSByte(int)
public static sbyte ToSByte(int value)
Parameters
valueint
Returns
ToSByte(long)
public static sbyte ToSByte(long value)
Parameters
valuelong
Returns
ToSByte(Complex)
public static sbyte ToSByte(Complex value)
Parameters
valueComplex
Returns
ToSByte(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to SByte: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToSByte(string)),
anything else through its IConvertible.
public static sbyte ToSByte(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- sbyte
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToSByte(object, IFormatProvider)
public static sbyte ToSByte(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToSByte(sbyte)
public static sbyte ToSByte(sbyte value)
Parameters
valuesbyte
Returns
ToSByte(float)
public static sbyte ToSByte(float value)
Parameters
valuefloat
Returns
ToSByte(string)
Converts a Python str to int8 as NumPy stores it into a int8 array (a[0] = text):
CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.
public static sbyte ToSByte(string value)
Parameters
Returns
- sbyte
The int8 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside int8 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToSByte(string, IFormatProvider)
ToSByte(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static sbyte ToSByte(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives 0.
providerIFormatProviderIgnored.
Returns
- sbyte
The int8 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside int8 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToSByte(TimeSpan)
public static sbyte ToSByte(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToSByte(ushort)
public static sbyte ToSByte(ushort value)
Parameters
valueushort
Returns
ToSByte(uint)
public static sbyte ToSByte(uint value)
Parameters
valueuint
Returns
ToSByte(ulong)
public static sbyte ToSByte(ulong value)
Parameters
valueulong
Returns
ToSingle(Char8)
public static float ToSingle(Char8 value)
Parameters
valueChar8
Returns
ToSingle(DateTime64)
public static float ToSingle(DateTime64 value)
Parameters
valueDateTime64
Returns
ToSingle(NDArray)
public static float ToSingle(NDArray nd)
Parameters
ndNDArray
Returns
ToSingle(bool)
public static float ToSingle(bool value)
Parameters
valuebool
Returns
ToSingle(byte)
public static float ToSingle(byte value)
Parameters
valuebyte
Returns
ToSingle(char)
public static float ToSingle(char value)
Parameters
valuechar
Returns
ToSingle(DateTime)
public static float ToSingle(DateTime value)
Parameters
valueDateTime
Returns
ToSingle(decimal)
public static float ToSingle(decimal value)
Parameters
valuedecimal
Returns
ToSingle(double)
public static float ToSingle(double value)
Parameters
valuedouble
Returns
ToSingle(Half)
float16 → float32, exact, with NumPy's NaN rule (npy_halfbits_to_floatbits): a NaN keeps its sign
and payload and a SIGNALLING NaN stays signalling — the BCL cast sets the quiet bit.
public static float ToSingle(Half value)
Parameters
valueHalfThe value to convert.
Returns
- float
The same value as float32 (every float16 is exactly representable).
ToSingle(short)
public static float ToSingle(short value)
Parameters
valueshort
Returns
ToSingle(int)
public static float ToSingle(int value)
Parameters
valueint
Returns
ToSingle(long)
public static float ToSingle(long value)
Parameters
valuelong
Returns
ToSingle(Complex)
public static float ToSingle(Complex value)
Parameters
valueComplex
Returns
ToSingle(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to Single: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToSingle(string)),
anything else through its IConvertible.
public static float ToSingle(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- float
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToSingle(object, IFormatProvider)
public static float ToSingle(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToSingle(sbyte)
public static float ToSingle(sbyte value)
Parameters
valuesbyte
Returns
ToSingle(float)
public static float ToSingle(float value)
Parameters
valuefloat
Returns
ToSingle(string)
Converts a Python str to float32 as NumPy stores it into a float32 array (a[0] = text):
CPython's float() grammar (whitespace, underscores between digits, inf / nan in any case), culture-invariant.
The parsed float64 is rounded once more into float32, as NumPy's store rounds it.
public static float ToSingle(string value)
Parameters
Returns
- float
The float32 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').
ToSingle(string, IFormatProvider)
ToSingle(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static float ToSingle(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives 0.
providerIFormatProviderIgnored.
Returns
- float
The float32 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').
ToSingle(TimeSpan)
public static float ToSingle(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToSingle(ushort)
public static float ToSingle(ushort value)
Parameters
valueushort
Returns
ToSingle(uint)
public static float ToSingle(uint value)
Parameters
valueuint
Returns
ToSingle(ulong)
uint64 → float32, rounded ONCE to nearest-even as NumPy's C cast does — not .NET 8's conversion, which goes through float64 and rounds twice (2⁶⁰ + 2³⁶ + 1 → 0x5D800000 instead of NumPy's 0x5D800001).
public static float ToSingle(ulong value)
Parameters
valueulongThe value to convert.
Returns
- float
The float32 nearest
value, ties to even.
ToString(Char8)
Returns a 1-character string (Latin-1 decode of the byte).
public static string ToString(Char8 value)
Parameters
valueChar8
Returns
ToString(DateTime64)
public static string ToString(DateTime64 value)
Parameters
valueDateTime64
Returns
ToString(DateTime64, IFormatProvider)
public static string ToString(DateTime64 value, IFormatProvider provider)
Parameters
valueDateTime64providerIFormatProvider
Returns
ToString(bool)
NumPy's str() of a bool value — the text astype('U') writes for it: True / False. Culture-invariant.
public static string ToString(bool value)
Parameters
valueboolThe value.
Returns
- string
The text.
ToString(bool, IFormatProvider)
ToString(bool): NumPy's text has no culture, so provider is ignored.
public static string ToString(bool value, IFormatProvider provider)
Parameters
valueboolThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(byte)
NumPy's str() of a uint8 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.
public static string ToString(byte value)
Parameters
valuebyteThe value.
Returns
- string
The text.
ToString(byte, IFormatProvider)
ToString(byte): NumPy's text has no culture, so provider is ignored.
public static string ToString(byte value, IFormatProvider provider)
Parameters
valuebyteThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(char)
NumPy's str() of a char value — the text astype('U') writes for it: its uint16 number ('a' → "97"): NumSharp's char dtype crosses to text as a uint16, as astype('U') writes it. Culture-invariant.
public static string ToString(char value)
Parameters
valuecharThe value.
Returns
- string
The text.
ToString(char, IFormatProvider)
ToString(char): NumPy's text has no culture, so provider is ignored.
public static string ToString(char value, IFormatProvider provider)
Parameters
valuecharThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(DateTime)
public static string ToString(DateTime value)
Parameters
valueDateTime
Returns
ToString(DateTime, IFormatProvider)
public static string ToString(DateTime value, IFormatProvider provider)
Parameters
valueDateTimeproviderIFormatProvider
Returns
ToString(decimal)
NumPy's str() of a decimal value — the text astype('U') writes for it: the float64 it converts to (NumSharp's decimal text rule; no NumPy analog). Culture-invariant.
public static string ToString(decimal value)
Parameters
valuedecimalThe value.
Returns
- string
The text.
ToString(decimal, IFormatProvider)
ToString(decimal): NumPy's text has no culture, so provider is ignored.
public static string ToString(decimal value, IFormatProvider provider)
Parameters
valuedecimalThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(double)
NumPy's str() of a float64 value — the text astype('U') writes for it: Python's repr of the float (1.0 → "1.0", 1e20 → "1e+20", NaN → "nan"). Culture-invariant.
public static string ToString(double value)
Parameters
valuedoubleThe value.
Returns
- string
The text.
ToString(double, IFormatProvider)
ToString(double): NumPy's text has no culture, so provider is ignored.
public static string ToString(double value, IFormatProvider provider)
Parameters
valuedoubleThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(Half)
NumPy's str() of a float16 value — the text astype('U') writes for it: its shortest round-trip digits
as float16 ((Half)0.1 → "0.1", (Half)65504 → "6.55e+04"). Culture-invariant.
public static string ToString(Half value)
Parameters
valueHalfThe value.
Returns
- string
The text.
ToString(Half, IFormatProvider)
ToString(Half): NumPy's text has no culture, so provider is ignored.
public static string ToString(Half value, IFormatProvider provider)
Parameters
valueHalfThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(short)
NumPy's str() of a int16 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.
public static string ToString(short value)
Parameters
valueshortThe value.
Returns
- string
The text.
ToString(short, IFormatProvider)
ToString(short): NumPy's text has no culture, so provider is ignored.
public static string ToString(short value, IFormatProvider provider)
Parameters
valueshortThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(int)
NumPy's str() of a int32 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.
public static string ToString(int value)
Parameters
valueintThe value.
Returns
- string
The text.
ToString(int, IFormatProvider)
ToString(int): NumPy's text has no culture, so provider is ignored.
public static string ToString(int value, IFormatProvider provider)
Parameters
valueintThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(long)
NumPy's str() of a int64 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.
public static string ToString(long value)
Parameters
valuelongThe value.
Returns
- string
The text.
ToString(long, IFormatProvider)
ToString(long): NumPy's text has no culture, so provider is ignored.
public static string ToString(long value, IFormatProvider provider)
Parameters
valuelongThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(Complex)
NumPy's str() of a complex128 value — the text astype('U') writes for it: "(1+2j)", a pure
imaginary value as "2j", each part written like a float64 ("(nan+infj)"). Culture-invariant.
public static string ToString(Complex value)
Parameters
valueComplexThe value.
Returns
- string
The text.
ToString(Complex, IFormatProvider)
ToString(Complex): NumPy's text has no culture, so provider is
ignored.
public static string ToString(Complex value, IFormatProvider provider)
Parameters
valueComplexThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(object)
The text of a boxed value (ToString(object, IFormatProvider) with no provider): NumPy's str()
for a NumSharp dtype value, the value itself for a string.
public static string ToString(object value)
Parameters
valueobjectThe value; null gives the empty string.
Returns
- string
The text.
ToString(object, IFormatProvider)
The text of a boxed value: NumPy's str() for a value of one of NumSharp's dtypes (the text astype('U')
writes for it, culture-invariant), the value itself for a string, and .NET's text through
provider for anything else (a DateTime, a TimeSpan, another object).
public static string ToString(object value, IFormatProvider provider)
Parameters
valueobjectThe value; null gives the empty string.
providerIFormatProviderThe format provider for a value that is not a NumSharp dtype value; ignored otherwise.
Returns
- string
The text.
ToString(sbyte)
NumPy's str() of a int8 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.
public static string ToString(sbyte value)
Parameters
valuesbyteThe value.
Returns
- string
The text.
ToString(sbyte, IFormatProvider)
ToString(sbyte): NumPy's text has no culture, so provider is ignored.
public static string ToString(sbyte value, IFormatProvider provider)
Parameters
valuesbyteThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(float)
NumPy's str() of a float32 value — the text astype('U') writes for it: its shortest round-trip digits as float32 (0.1f → "0.1", 1e20f → "1e+20"). Culture-invariant.
public static string ToString(float value)
Parameters
valuefloatThe value.
Returns
- string
The text.
ToString(float, IFormatProvider)
ToString(float): NumPy's text has no culture, so provider is ignored.
public static string ToString(float value, IFormatProvider provider)
Parameters
valuefloatThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(string)
public static string ToString(string value)
Parameters
valuestring
Returns
ToString(string, IFormatProvider)
public static string ToString(string value, IFormatProvider provider)
Parameters
valuestringproviderIFormatProvider
Returns
ToString(ushort)
NumPy's str() of a uint16 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.
public static string ToString(ushort value)
Parameters
valueushortThe value.
Returns
- string
The text.
ToString(ushort, IFormatProvider)
ToString(ushort): NumPy's text has no culture, so provider is ignored.
public static string ToString(ushort value, IFormatProvider provider)
Parameters
valueushortThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(uint)
NumPy's str() of a uint32 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.
public static string ToString(uint value)
Parameters
valueuintThe value.
Returns
- string
The text.
ToString(uint, IFormatProvider)
ToString(uint): NumPy's text has no culture, so provider is ignored.
public static string ToString(uint value, IFormatProvider provider)
Parameters
valueuintThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToString(ulong)
NumPy's str() of a uint64 value — the text astype('U') writes for it: its decimal digits. Culture-invariant.
public static string ToString(ulong value)
Parameters
valueulongThe value.
Returns
- string
The text.
ToString(ulong, IFormatProvider)
ToString(ulong): NumPy's text has no culture, so provider is ignored.
public static string ToString(ulong value, IFormatProvider provider)
Parameters
valueulongThe value.
providerIFormatProviderIgnored.
Returns
- string
The text.
ToTimeSpan(DateTime64)
public static TimeSpan ToTimeSpan(DateTime64 value)
Parameters
valueDateTime64
Returns
ToTimeSpan(bool)
public static TimeSpan ToTimeSpan(bool value)
Parameters
valuebool
Returns
ToTimeSpan(byte)
public static TimeSpan ToTimeSpan(byte value)
Parameters
valuebyte
Returns
ToTimeSpan(char)
public static TimeSpan ToTimeSpan(char value)
Parameters
valuechar
Returns
ToTimeSpan(DateTime)
public static TimeSpan ToTimeSpan(DateTime value)
Parameters
valueDateTime
Returns
ToTimeSpan(decimal)
public static TimeSpan ToTimeSpan(decimal value)
Parameters
valuedecimal
Returns
ToTimeSpan(double)
public static TimeSpan ToTimeSpan(double value)
Parameters
valuedouble
Returns
ToTimeSpan(Half)
public static TimeSpan ToTimeSpan(Half value)
Parameters
valueHalf
Returns
ToTimeSpan(short)
public static TimeSpan ToTimeSpan(short value)
Parameters
valueshort
Returns
ToTimeSpan(int)
public static TimeSpan ToTimeSpan(int value)
Parameters
valueint
Returns
ToTimeSpan(long)
public static TimeSpan ToTimeSpan(long value)
Parameters
valuelong
Returns
ToTimeSpan(Complex)
public static TimeSpan ToTimeSpan(Complex value)
Parameters
valueComplex
Returns
ToTimeSpan(object)
public static TimeSpan ToTimeSpan(object value)
Parameters
valueobject
Returns
ToTimeSpan(sbyte)
public static TimeSpan ToTimeSpan(sbyte value)
Parameters
valuesbyte
Returns
ToTimeSpan(float)
public static TimeSpan ToTimeSpan(float value)
Parameters
valuefloat
Returns
ToTimeSpan(string)
public static TimeSpan ToTimeSpan(string value)
Parameters
valuestring
Returns
ToTimeSpan(string, IFormatProvider)
public static TimeSpan ToTimeSpan(string value, IFormatProvider provider)
Parameters
valuestringproviderIFormatProvider
Returns
ToTimeSpan(TimeSpan)
public static TimeSpan ToTimeSpan(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToTimeSpan(ushort)
public static TimeSpan ToTimeSpan(ushort value)
Parameters
valueushort
Returns
ToTimeSpan(uint)
public static TimeSpan ToTimeSpan(uint value)
Parameters
valueuint
Returns
ToTimeSpan(ulong)
public static TimeSpan ToTimeSpan(ulong value)
Parameters
valueulong
Returns
ToUInt16(Char8)
public static ushort ToUInt16(Char8 value)
Parameters
valueChar8
Returns
ToUInt16(DateTime64)
public static ushort ToUInt16(DateTime64 value)
Parameters
valueDateTime64
Returns
ToUInt16(NDArray)
public static ushort ToUInt16(NDArray nd)
Parameters
ndNDArray
Returns
ToUInt16(bool)
public static ushort ToUInt16(bool value)
Parameters
valuebool
Returns
ToUInt16(byte)
public static ushort ToUInt16(byte value)
Parameters
valuebyte
Returns
ToUInt16(char)
public static ushort ToUInt16(char value)
Parameters
valuechar
Returns
ToUInt16(DateTime)
public static ushort ToUInt16(DateTime value)
Parameters
valueDateTime
Returns
ToUInt16(decimal)
public static ushort ToUInt16(decimal value)
Parameters
valuedecimal
Returns
ToUInt16(double)
public static ushort ToUInt16(double value)
Parameters
valuedouble
Returns
ToUInt16(Half)
public static ushort ToUInt16(Half value)
Parameters
valueHalf
Returns
ToUInt16(short)
public static ushort ToUInt16(short value)
Parameters
valueshort
Returns
ToUInt16(int)
public static ushort ToUInt16(int value)
Parameters
valueint
Returns
ToUInt16(long)
public static ushort ToUInt16(long value)
Parameters
valuelong
Returns
ToUInt16(Complex)
public static ushort ToUInt16(Complex value)
Parameters
valueComplex
Returns
ToUInt16(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to UInt16: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToUInt16(string)),
anything else through its IConvertible.
public static ushort ToUInt16(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- ushort
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToUInt16(object, IFormatProvider)
public static ushort ToUInt16(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToUInt16(sbyte)
public static ushort ToUInt16(sbyte value)
Parameters
valuesbyte
Returns
ToUInt16(float)
public static ushort ToUInt16(float value)
Parameters
valuefloat
Returns
ToUInt16(string)
Converts a Python str to uint16 as NumPy stores it into a uint16 array (a[0] = text):
CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.
public static ushort ToUInt16(string value)
Parameters
Returns
- ushort
The uint16 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside uint16 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToUInt16(string, IFormatProvider)
ToUInt16(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static ushort ToUInt16(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives 0.
providerIFormatProviderIgnored.
Returns
- ushort
The uint16 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside uint16 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToUInt16(TimeSpan)
public static ushort ToUInt16(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToUInt16(ushort)
public static ushort ToUInt16(ushort value)
Parameters
valueushort
Returns
ToUInt16(uint)
public static ushort ToUInt16(uint value)
Parameters
valueuint
Returns
ToUInt16(ulong)
public static ushort ToUInt16(ulong value)
Parameters
valueulong
Returns
ToUInt32(Char8)
public static uint ToUInt32(Char8 value)
Parameters
valueChar8
Returns
ToUInt32(DateTime64)
public static uint ToUInt32(DateTime64 value)
Parameters
valueDateTime64
Returns
ToUInt32(NDArray)
public static uint ToUInt32(NDArray nd)
Parameters
ndNDArray
Returns
ToUInt32(bool)
public static uint ToUInt32(bool value)
Parameters
valuebool
Returns
ToUInt32(byte)
public static uint ToUInt32(byte value)
Parameters
valuebyte
Returns
ToUInt32(char)
public static uint ToUInt32(char value)
Parameters
valuechar
Returns
ToUInt32(DateTime)
public static uint ToUInt32(DateTime value)
Parameters
valueDateTime
Returns
ToUInt32(decimal)
public static uint ToUInt32(decimal value)
Parameters
valuedecimal
Returns
ToUInt32(double)
public static uint ToUInt32(double value)
Parameters
valuedouble
Returns
ToUInt32(Half)
public static uint ToUInt32(Half value)
Parameters
valueHalf
Returns
ToUInt32(short)
public static uint ToUInt32(short value)
Parameters
valueshort
Returns
ToUInt32(int)
public static uint ToUInt32(int value)
Parameters
valueint
Returns
ToUInt32(long)
public static uint ToUInt32(long value)
Parameters
valuelong
Returns
ToUInt32(Complex)
public static uint ToUInt32(Complex value)
Parameters
valueComplex
Returns
ToUInt32(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to UInt32: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToUInt32(string)),
anything else through its IConvertible.
public static uint ToUInt32(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- uint
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToUInt32(object, IFormatProvider)
public static uint ToUInt32(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToUInt32(sbyte)
public static uint ToUInt32(sbyte value)
Parameters
valuesbyte
Returns
ToUInt32(float)
public static uint ToUInt32(float value)
Parameters
valuefloat
Returns
ToUInt32(string)
Converts a Python str to uint32 as NumPy stores it into a uint32 array (a[0] = text):
CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.
public static uint ToUInt32(string value)
Parameters
Returns
- uint
The uint32 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside uint32 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToUInt32(string, IFormatProvider)
ToUInt32(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static uint ToUInt32(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives 0.
providerIFormatProviderIgnored.
Returns
- uint
The uint32 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside uint32 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToUInt32(TimeSpan)
public static uint ToUInt32(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToUInt32(ushort)
public static uint ToUInt32(ushort value)
Parameters
valueushort
Returns
ToUInt32(uint)
public static uint ToUInt32(uint value)
Parameters
valueuint
Returns
ToUInt32(ulong)
public static uint ToUInt32(ulong value)
Parameters
valueulong
Returns
ToUInt64(Char8)
public static ulong ToUInt64(Char8 value)
Parameters
valueChar8
Returns
ToUInt64(DateTime64)
public static ulong ToUInt64(DateTime64 value)
Parameters
valueDateTime64
Returns
ToUInt64(NDArray)
public static ulong ToUInt64(NDArray nd)
Parameters
ndNDArray
Returns
ToUInt64(bool)
public static ulong ToUInt64(bool value)
Parameters
valuebool
Returns
ToUInt64(byte)
public static ulong ToUInt64(byte value)
Parameters
valuebyte
Returns
ToUInt64(char)
public static ulong ToUInt64(char value)
Parameters
valuechar
Returns
ToUInt64(DateTime)
public static ulong ToUInt64(DateTime value)
Parameters
valueDateTime
Returns
ToUInt64(decimal)
public static ulong ToUInt64(decimal value)
Parameters
valuedecimal
Returns
ToUInt64(double)
public static ulong ToUInt64(double value)
Parameters
valuedouble
Returns
ToUInt64(Half)
public static ulong ToUInt64(Half value)
Parameters
valueHalf
Returns
ToUInt64(short)
public static ulong ToUInt64(short value)
Parameters
valueshort
Returns
ToUInt64(int)
public static ulong ToUInt64(int value)
Parameters
valueint
Returns
ToUInt64(long)
public static ulong ToUInt64(long value)
Parameters
valuelong
Returns
ToUInt64(Complex)
public static ulong ToUInt64(Complex value)
Parameters
valueComplex
Returns
ToUInt64(object)
Converts a boxed value of any NumSharp dtype (or a Python str) to UInt64: a number by NumPy's cast rules
(the element astype writes), a string by NumPy's text rules (ToUInt64(string)),
anything else through its IConvertible.
public static ulong ToUInt64(object value)
Parameters
valueobjectThe value; null gives the default.
Returns
- ulong
The converted value.
Exceptions
- ValueError
A str that is not a literal of the target's kind.
- OverflowError
A str holding an integer outside an integer target.
- InvalidCastException
A value that is neither a dtype value, a str nor IConvertible.
ToUInt64(object, IFormatProvider)
public static ulong ToUInt64(object value, IFormatProvider provider)
Parameters
valueobjectproviderIFormatProvider
Returns
ToUInt64(sbyte)
public static ulong ToUInt64(sbyte value)
Parameters
valuesbyte
Returns
ToUInt64(float)
public static ulong ToUInt64(float value)
Parameters
valuefloat
Returns
ToUInt64(string)
Converts a Python str to uint64 as NumPy stores it into a uint64 array (a[0] = text):
CPython's int() grammar (whitespace, a sign, underscores between digits, non-ASCII decimal digits), culture-invariant.
public static ulong ToUInt64(string value)
Parameters
Returns
- ulong
The uint64 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside uint64 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToUInt64(string, IFormatProvider)
ToUInt64(string): NumPy's text has no culture, so provider is ignored (the
parameter keeps Convert's signature).
public static ulong ToUInt64(string value, IFormatProvider provider)
Parameters
valuestringThe text; null gives 0.
providerIFormatProviderIgnored.
Returns
- ulong
The uint64 value.
Exceptions
- ValueError
The text is not a literal of the target's kind (CPython's text, quoting the str:
invalid literal for int() with base 10: '1.5',could not convert string to float: 'x').- OverflowError
The integer is outside uint64 (NumPy's
Python integer 300 out of bounds for uint8, orPython int too large to convert to C long).
ToUInt64(TimeSpan)
public static ulong ToUInt64(TimeSpan value)
Parameters
valueTimeSpan
Returns
ToUInt64(ushort)
public static ulong ToUInt64(ushort value)
Parameters
valueushort
Returns
ToUInt64(uint)
public static ulong ToUInt64(uint value)
Parameters
valueuint
Returns
ToUInt64(ulong)
public static ulong ToUInt64(ulong value)
Parameters
valueulong