|
char * | strmake (char *dst, const char *src, size_t length) |
|
char * | strcont (char *src, const char *set) |
|
char * | strxmov (char *dst, const char *src,...) |
|
char * | strxnmov (char *dst, size_t len, const char *src,...) |
|
static void | bchange (uchar *dst, size_t old_length, const uchar *src, size_t new_length, size_t tot_length) |
|
static const char * | strend (const char *s) |
|
static char * | strend (char *s) |
|
static const char * | strcend (const char *s, char c) |
|
static char * | strfill (char *s, size_t len, char fill) |
|
static char * | my_stpmov (char *dst, const char *src) |
|
static char * | my_stpnmov (char *dst, const char *src, size_t n) |
|
static char * | my_stpcpy (char *dst, const char *src) |
| Copy a string from src to dst until (and including) terminating null byte. More...
|
|
static char * | my_stpncpy (char *dst, const char *src, size_t n) |
| Copy fixed-size string from src to dst. More...
|
|
static longlong | my_strtoll (const char *nptr, char **endptr, int base) |
|
static ulonglong | my_strtoull (const char *nptr, char **endptr, int base) |
|
static char * | my_strtok_r (char *str, const char *delim, char **saveptr) |
|
static int | native_strcasecmp (const char *s1, const char *s2) |
|
static int | native_strncasecmp (const char *s1, const char *s2, size_t n) |
|
static int | is_prefix (const char *s, const char *t) |
|
double | my_strtod (const char *str, const char **end, int *error) |
| Converts string to double (string does not have to be zero-terminated) More...
|
|
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...
|
|
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...
|
|
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...
|
|
const char * | str2int (const char *src, int radix, long lower, long upper, long *val) |
|
longlong | my_strtoll10 (const char *nptr, const char **endptr, int *error) |
|
char * | ll2str (int64_t val, char *dst, int radix, bool upcase) |
| Converts a 64-bit integer value to its character form and moves it to the destination buffer followed by a terminating NUL. More...
|
|
char * | longlong10_to_str (int64_t val, char *dst, int radix) |
| Converts a 64-bit integer to its string representation in decimal notation. More...
|
|
char * | longlong2str (int64_t val, char *dst, int radix) |
|
static char * | llstr (longlong value, char *buff) |
|
static char * | ullstr (longlong value, char *buff) |
|
static const uchar * | skip_trailing_space (const uchar *ptr, size_t len) |
| Skip trailing space (ASCII spaces only). More...
|
|
static void | human_readable_num_bytes (char *buf, int buf_len, double dbl_val) |
|
static void | lex_string_set (LEX_STRING *lex_str, char *c_str) |
|
static void | lex_cstring_set (LEX_CSTRING *lex_str, const char *c_str) |
|
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:
- the conversion is usually more precise than C library functions.
- there is no 'precision' argument. instead, we specify the number of characters available for conversion (i.e. a field width).
- the result never exceeds the specified field width. If the field is too short to contain even a rounded decimal representation, my_gcvt() indicates overflow and truncates the output string to the specified width.
- float-type arguments are handled differently than double ones. For a float input number (i.e. when the 'type' argument is MY_GCVT_ARG_FLOAT) we deliberately limit the precision of conversion by FLT_DIG digits to avoid garbage past the significant digits.
- unlike sprintf(), in cases where the 'e' format is preferred, we don't zero-pad the exponent to save space for significant digits. The '+' sign for a positive exponent does not appear for the same reason.
- Parameters
-
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'. |
- Returns
- number of written characters (excluding terminating '\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:
- passing to dtoa() the field width as the number of significant digits
- removing the sign of the number early (and decreasing the width before passing it to dtoa())
- choosing the proper format to preserve the most number of significant digits.