rwskit.numeric
Utilities for numeric operations.
Attributes
Functions
|
Convert a string s to an integer. If s is None return None |
|
Convert a string s to a float. If s is None return None |
|
If the value is positive, this will return a signed version of the number |
Module Contents
- rwskit.numeric.int_(s: str | None, falsy_as_none: bool = True) int | None[source]
Convert a string s to an integer. If s is None return None instead of raising an exception.
- Parameters:
s (str, optional) – The string to convert.
falsy_as_none (bool, default=True) – If True all falsy values of s (other than
0) will return None, otherwise only None values will be passed through and an exception will be raised.
- Returns:
None if s is None, otherwise an integer if s is not None and is parseable.
- Return type:
int, optional
- Raises:
ValueError – If the string cannot be parsed.
- rwskit.numeric.float_(s: str | None, falsy_as_none: bool = True) float | None[source]
Convert a string s to a float. If s is None return None instead of raising an exception.
- Parameters:
s (str, optional) – The string to convert.
falsy_as_none (bool, default=True) – If True all falsy values of s will return None (other than
0), otherwise only None values will be passed through and an exception will be raised..
- Returns:
None if s is None, otherwise a float if s is not None and is parseable.
- Return type:
float, optional
- Raises:
ValueError – If the string cannot be parsed.
- rwskit.numeric.to_signed(value: int) int[source]
If the value is positive, this will return a signed version of the number that fits in the same size integer type. For example,
129is a valid 8-bit signed integer, but a 16-bit unsigned integer. This method will convert the number to the corresponding signed integer that still fits in 8-bits. In this case127.- Parameters:
value (int) – The value to convert.
- Returns:
The signed version.
- Return type:
int
- Raises:
ValueError – If the
valueis more than 64-bits.