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