Classes | |
struct | Precision |
struct | ToStringOptions |
Enumerations | |
enum class | TrimTrailingZerosType |
enum class | PredefinedLocale { } |
enum class | FloatFormatType |
Functions | |
template<typename STRING_TYPE = String, floating_point FLOAT_TYPE = float> | |
STRING_TYPE | ToString (FLOAT_TYPE f, const ToStringOptions &options={}) |
template<floating_point T = double, IUNICODECanUnambiguouslyConvertFrom CHAR_T> | |
T | ToFloat (span< const CHAR_T > s) |
TODO:
using PrecisionType = uint16_t;
|
strong |
Control needless trailing zeros. For example, 3.000 instead of 3, or 4.2000 versus 4.2. Sometimes desirable (to show precision). But often not.
Definition at line 40 of file FloatConversion.h.
|
strong |
Definition at line 49 of file FloatConversion.h.
|
strong |
Automatic picks based on the precision and the number used, so for example, 0.0000001 will show as '1e-7', but 4 will show as '4'
eScientific corresponds to ios_base::scientific eFixedPoint corresponds to ios_base::fixed eDefaultFloat corresponds to unsetf (floatfield) - which may be different than scientific or fixed point
Definition at line 153 of file FloatConversion.h.
STRING_TYPE Stroika::Foundation::Characters::FloatConversion::ToString | ( | FLOAT_TYPE | f, |
const ToStringOptions & | options = {} |
||
) |
ToString converts a floating point number to a string, controlled by parameterized options.
ToString () maps NAN values to the string "NAN", and negative infinite values to "-INF", and positive infinite values to "INF" (note NAN/INF are case insensitive).
The supported type values for FLOAT_TYPE are: o float o double o long double
The supported type values for RESULT_TYPE are: o String o string o wstring o ... but this could sensibly be extended in the future
T Stroika::Foundation::Characters::FloatConversion::ToFloat | ( | span< const CHAR_T > | s | ) |
ToFloat all overloads: Convert the given decimal-format floating point string to an float, double, or long double.
ToFloat will return nan () if no valid parse (for example, -1.#INF000000000000 is, invalid and returns nan, despite the fact that this is often emitted by the MSFT sprintf() for inf values).
The overloads taking string or const char* arguments Require() that the input is ASCII ('C' locale required/assumed). (
If the argument value is too large or too small to fit in 'T' (ERANGE) - then the value will be pinned to -numeric_limits<T>::infinity () or numeric_limits<T>::infinity ().
If the input string is INF or INFINITY (with an optional +/- prefix) - the returned value will be the appropriate version of infinity.
If the argument is the string "NAN", a quiet NAN will be returned. If the string -INF or -INFINITY, a negative infinite float will be returned, and if INF or INFINITY is passed, a positive infinite value will be returned:
ToFloat (no remainder parameter): The argument should be pre-trimmed (whitespace). If there is any leading or trailing garbage (even whitespace) this function will return nan() (note - unlike overload with 'remainder' arg).
ToFloat (with remainder parameter): Logically a simple wrapper on std::wcstof, std::wcstod, std::wcstold - except using String class, and returns the unused portion of the string in the REQUIRED remainder OUT parameter.
This means it ALLOWS leading whitespace (skipped). And it allows junk at the end (remainder parameter filled in with what).
// @todo redo all these with some concept to make it shorter - like ISCOVNERTIBLE TO STRING
Definition at line 645 of file FloatConversion.inl.