]>
Commit | Line | Data |
---|---|---|
e18a3057 | 1 | /* Compatibility functions for floating point formatting. |
2b778ceb | 2 | Copyright (C) 1995-2021 Free Software Foundation, Inc. |
e18a3057 GG |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
17 | <https://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #include <math.h> | |
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | #include <sys/param.h> | |
23 | #include <libc-lock.h> | |
24 | #include <math_ldbl_opt.h> | |
25 | ||
3021e781 GG |
26 | #ifndef SPRINTF |
27 | # define SPRINTF sprintf | |
28 | #endif | |
29 | ||
e18a3057 GG |
30 | #define APPEND(a, b) APPEND2 (a, b) |
31 | #define APPEND2(a, b) a##b | |
e18a3057 GG |
32 | |
33 | ||
34 | #define FCVT_BUFFER APPEND (FUNC_PREFIX, fcvt_buffer) | |
35 | #define FCVT_BUFPTR APPEND (FUNC_PREFIX, fcvt_bufptr) | |
36 | #define ECVT_BUFFER APPEND (FUNC_PREFIX, ecvt_buffer) | |
37 | ||
38 | ||
39 | static char FCVT_BUFFER[MAXDIG]; | |
40 | static char ECVT_BUFFER[MAXDIG]; | |
41 | libc_freeres_ptr (static char *FCVT_BUFPTR); | |
42 | ||
43 | char * | |
dce42534 | 44 | __FCVT (FLOAT_TYPE value, int ndigit, int *decpt, int *sign) |
e18a3057 GG |
45 | { |
46 | if (FCVT_BUFPTR == NULL) | |
47 | { | |
dce42534 | 48 | if (__FCVT_R (value, ndigit, decpt, sign, FCVT_BUFFER, MAXDIG) != -1) |
e18a3057 GG |
49 | return FCVT_BUFFER; |
50 | ||
51 | FCVT_BUFPTR = (char *) malloc (FCVT_MAXDIG); | |
52 | if (FCVT_BUFPTR == NULL) | |
53 | return FCVT_BUFFER; | |
54 | } | |
55 | ||
dce42534 | 56 | (void) __FCVT_R (value, ndigit, decpt, sign, FCVT_BUFPTR, FCVT_MAXDIG); |
e18a3057 GG |
57 | |
58 | return FCVT_BUFPTR; | |
59 | } | |
60 | ||
61 | ||
62 | char * | |
dce42534 | 63 | __ECVT (FLOAT_TYPE value, int ndigit, int *decpt, int *sign) |
e18a3057 | 64 | { |
dce42534 | 65 | (void) __ECVT_R (value, ndigit, decpt, sign, ECVT_BUFFER, MAXDIG); |
e18a3057 GG |
66 | |
67 | return ECVT_BUFFER; | |
68 | } | |
69 | ||
70 | char * | |
dce42534 | 71 | __GCVT (FLOAT_TYPE value, int ndigit, char *buf) |
e18a3057 | 72 | { |
3021e781 | 73 | SPRINTF (buf, "%.*" FLOAT_FMT_FLAG "g", MIN (ndigit, NDIGIT_MAX), value); |
e18a3057 GG |
74 | return buf; |
75 | } |