PostgreSQL Source Code  git master
shortest_dec.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------
2  *
3  * Ryu floating-point output.
4  *
5  * Portions Copyright (c) 2018-2024, PostgreSQL Global Development Group
6  *
7  * IDENTIFICATION
8  * src/include/common/shortest_dec.h
9  *
10  * This is a modification of code taken from github.com/ulfjack/ryu under the
11  * terms of the Boost license (not the Apache license). The original copyright
12  * notice follows:
13  *
14  * Copyright 2018 Ulf Adams
15  *
16  * The contents of this file may be used under the terms of the Apache
17  * License, Version 2.0.
18  *
19  * (See accompanying file LICENSE-Apache or copy at
20  * http://www.apache.org/licenses/LICENSE-2.0)
21  *
22  * Alternatively, the contents of this file may be used under the terms of the
23  * Boost Software License, Version 1.0.
24  *
25  * (See accompanying file LICENSE-Boost or copy at
26  * https://www.boost.org/LICENSE_1_0.txt)
27  *
28  * Unless required by applicable law or agreed to in writing, this software is
29  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
30  * KIND, either express or implied.
31  *
32  *---------------------------------------------------------------------------
33  */
34 #ifndef SHORTEST_DEC_H
35 #define SHORTEST_DEC_H
36 
37 /*----
38  * The length of 25 comes from:
39  *
40  * Case 1: -9.9999999999999999e-299 = 24 bytes, plus 1 for null
41  *
42  * Case 2: -0.00099999999999999999 = 23 bytes, plus 1 for null
43  */
44 #define DOUBLE_SHORTEST_DECIMAL_LEN 25
45 
46 int double_to_shortest_decimal_bufn(double f, char *result);
47 int double_to_shortest_decimal_buf(double f, char *result);
48 char *double_to_shortest_decimal(double f);
49 
50 /*
51  * The length of 16 comes from:
52  *
53  * Case 1: -9.99999999e+29 = 15 bytes, plus 1 for null
54  *
55  * Case 2: -0.000999999999 = 15 bytes, plus 1 for null
56  */
57 #define FLOAT_SHORTEST_DECIMAL_LEN 16
58 
59 int float_to_shortest_decimal_bufn(float f, char *result);
60 int float_to_shortest_decimal_buf(float f, char *result);
61 char *float_to_shortest_decimal(float f);
62 
63 #endif /* SHORTEST_DEC_H */
char * double_to_shortest_decimal(double f)
Definition: d2s.c:1070
int double_to_shortest_decimal_bufn(double f, char *result)
Definition: d2s.c:1015
int float_to_shortest_decimal_buf(float f, char *result)
Definition: f2s.c:780
int float_to_shortest_decimal_bufn(float f, char *result)
Definition: f2s.c:742
char * float_to_shortest_decimal(float f)
Definition: f2s.c:797
int double_to_shortest_decimal_buf(double f, char *result)
Definition: d2s.c:1053