MySQL 9.1.0
Source Code Documentation
|
Go to the source code of this file.
Macros | |
#define | MAX_DECPT_FOR_F_FORMAT DBL_DIG |
#define | MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + std::max(5, MAX_DECPT_FOR_F_FORMAT)) |
Enumerations | |
enum | my_gcvt_arg_type { MY_GCVT_ARG_FLOAT , MY_GCVT_ARG_DOUBLE } |
Functions | |
MYSQL_STRINGS_EXPORT double | my_strtod (const char *str, const char **end, int *error) |
Converts string to double (string does not have to be zero-terminated) More... | |
MYSQL_STRINGS_EXPORT size_t | my_fcvt (double x, int precision, char *to, bool *error) |
Converts a given floating point number to a zero-terminated string representation using the 'f' format. More... | |
MYSQL_STRINGS_EXPORT size_t | my_fcvt_no_trailing_zero (double x, int precision, char *to, bool *error) |
Identical to my_fcvt, except that trailing zeros after the decimal point will be removed. More... | |
MYSQL_STRINGS_EXPORT size_t | my_fcvt_compact (double x, char *to, bool *error) |
Converts a given floating point number to a zero-terminated string representation using the 'f' format. More... | |
MYSQL_STRINGS_EXPORT size_t | my_gcvt (double x, my_gcvt_arg_type type, int width, char *to, bool *error) |
Converts a given floating point number to a zero-terminated string representation with a given field width using the 'e' format (aka scientific notation) or the 'f' one. More... | |
Variables | |
static constexpr int | DECIMAL_MAX_SCALE {30} |
static constexpr int | DECIMAL_NOT_SPECIFIED {DECIMAL_MAX_SCALE + 1} |
static constexpr int | FLOATING_POINT_BUFFER {311 + DECIMAL_NOT_SPECIFIED} |
#define MAX_DECPT_FOR_F_FORMAT DBL_DIG |
#define MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + std::max(5, MAX_DECPT_FOR_F_FORMAT)) |
enum my_gcvt_arg_type |
MYSQL_STRINGS_EXPORT size_t my_fcvt | ( | double | x, |
int | precision, | ||
char * | to, | ||
bool * | error | ||
) |
Converts a given floating point number to a zero-terminated string representation using the 'f' format.
This function is a wrapper around dtoa() to do the same as sprintf(to, "%-.*f", precision, x), though the conversion is usually more precise. The only difference is in handling [-,+]infinity and nan values, in which case we print '0\0' to the output string and indicate an overflow.
x | the input floating point number. |
precision | the number of digits after the decimal point. All properties of sprintf() apply:
|
to | pointer to the output buffer. The longest string which my_fcvt() can return is FLOATING_POINT_BUFFER bytes (including the terminating '\0'). |
error | if not NULL, points to a location where the status of conversion is stored upon return. false successful conversion true the input number is [-,+]infinity or nan. The output string in this case is always '0'. |
MYSQL_STRINGS_EXPORT size_t my_fcvt_compact | ( | double | x, |
char * | to, | ||
bool * | error | ||
) |
Converts a given floating point number to a zero-terminated string representation using the 'f' format.
This function is a wrapper around dtoa() to do almost the same as sprintf(to, "%-.*f", precision, x), though the conversion is usually more precise. The only difference is in handling [-,+]infinity and nan values, in which case we print '0\0' to the output string and indicate an overflow.
The string always contains the minimum number of digits necessary to reproduce the same binary double value if the string is parsed back to a double value.
x | the input floating point number. |
to | pointer to the output buffer. The longest string which my_fcvt() can return is FLOATING_POINT_BUFFER bytes (including the terminating '\0'). |
error | if not NULL, points to a location where the status of conversion is stored upon return. false successful conversion true the input number is [-,+]infinity or nan. The output string in this case is always '0'. |
MYSQL_STRINGS_EXPORT size_t my_fcvt_no_trailing_zero | ( | double | x, |
int | precision, | ||
char * | to, | ||
bool * | error | ||
) |
Identical to my_fcvt, except that trailing zeros after the decimal point will be removed.
MYSQL_STRINGS_EXPORT size_t my_gcvt | ( | double | x, |
my_gcvt_arg_type | type, | ||
int | width, | ||
char * | to, | ||
bool * | error | ||
) |
Converts a given floating point number to a zero-terminated string representation with a given field width using the 'e' format (aka scientific notation) or the 'f' one.
The format is chosen automatically to provide the most number of significant digits (and thus, precision) with a given field width. In many cases, the result is similar to that of sprintf(to, "%g", x) with a few notable differences:
x | the input floating point number. |
type | is either MY_GCVT_ARG_FLOAT or MY_GCVT_ARG_DOUBLE. Specifies the type of the input number (see notes above). |
width | field width in characters. The minimal field width to hold any number representation (albeit rounded) is 7 characters ("-Ne-NNN"). |
to | pointer to the output buffer. The result is always zero-terminated, and the longest returned string is thus 'width + 1' bytes. |
error | if not NULL, points to a location where the status of conversion is stored upon return. false successful conversion true the input number is [-,+]infinity or nan. The output string in this case is always '0'. |
my_gcvt(-9e-3, ..., 4, ...); my_gcvt(-9e-3, ..., 2, ...); my_gcvt(1.87e-3, ..., 4, ...); my_gcvt(55, ..., 1, ...);
We do our best to minimize such cases by:
MYSQL_STRINGS_EXPORT double my_strtod | ( | const char * | str, |
const char ** | end, | ||
int * | error | ||
) |
Converts string to double (string does not have to be zero-terminated)
This is a wrapper around dtoa's version of strtod().
str | input string |
end | address of a pointer to the first character after the input string. Upon return the pointer is set to point to the first rejected character. |
error | Upon return is set to EOVERFLOW in case of underflow or overflow. |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |