MySQL 8.3.0
Source Code Documentation
dtoa.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 2023, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef INCLUDE_MYSQL_STRINGS_DTOA_H_
25#define INCLUDE_MYSQL_STRINGS_DTOA_H_
26
27#include <cfloat>
28#include <cstddef>
29
30#include "mysql/strings/api.h"
31
32/*
33 We want to use the 'e' format in some cases even if we have enough space
34 for the 'f' one just to mimic sprintf("%.15g") behavior for large integers,
35 and to improve it for numbers < 10^(-4).
36 That is, for |x| < 1 we require |x| >= 10^(-15), and for |x| > 1 we require
37 it to be integer and be <= 10^DBL_DIG for the 'f' format to be used.
38 We don't lose precision, but make cases like "1e200" or "0.00001" look nicer.
39*/
40#define MAX_DECPT_FOR_F_FORMAT DBL_DIG
41
42/*
43 The maximum possible field width for my_gcvt() conversion.
44 (DBL_DIG + 2) significant digits + sign + "." + ("e-NNN" or
45 MAX_DECPT_FOR_F_FORMAT zeros for cases when |x|<1 and the 'f' format is used).
46*/
47#define MY_GCVT_MAX_FIELD_WIDTH \
48 (DBL_DIG + 4 + std::max(5, MAX_DECPT_FOR_F_FORMAT))
49
51
52static constexpr int DECIMAL_MAX_SCALE{30};
53static constexpr int DECIMAL_NOT_SPECIFIED{DECIMAL_MAX_SCALE + 1};
54
55/*
56 The longest string my_fcvt can return is 311 + "precision" bytes.
57 Here we assume that we never call my_fcvt() with precision >=
58 DECIMAL_NOT_SPECIFIED
59 (+ 1 byte for the terminating '\0').
60*/
61static constexpr int FLOATING_POINT_BUFFER{311 + DECIMAL_NOT_SPECIFIED};
62
63/* Conversion routines */
64
65MYSQL_STRINGS_EXPORT double my_strtod(const char *str, const char **end,
66 int *error);
67MYSQL_STRINGS_EXPORT size_t my_fcvt(double x, int precision, char *to,
68 bool *error);
69MYSQL_STRINGS_EXPORT size_t my_fcvt_compact(double x, char *to, bool *error);
70MYSQL_STRINGS_EXPORT size_t my_gcvt(double x, my_gcvt_arg_type type, int width,
71 char *to, bool *error);
72
73#endif // INCLUDE_MYSQL_STRINGS_DTOA_H_
#define MYSQL_STRINGS_EXPORT
Definition: api.h:46
static constexpr int FLOATING_POINT_BUFFER
Definition: dtoa.h:61
static constexpr int DECIMAL_NOT_SPECIFIED
Definition: dtoa.h:53
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' forma...
Definition: dtoa.cc:233
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' forma...
Definition: dtoa.cc:202
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)
Definition: dtoa.cc:514
my_gcvt_arg_type
Definition: dtoa.h:50
@ MY_GCVT_ARG_DOUBLE
Definition: dtoa.h:50
@ MY_GCVT_ARG_FLOAT
Definition: dtoa.h:50
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 ...
Definition: dtoa.cc:301
static constexpr int DECIMAL_MAX_SCALE
Definition: dtoa.h:52
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1065
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
required string type
Definition: replication_group_member_actions.proto:33