1 /* Compatibility functions for floating point formatting.
2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
23 #include <bits/libc-lock.h>
26 # define FLOAT_TYPE double
28 # define FLOAT_FMT_FLAG
29 /* Actually we have to write (DBL_DIG + log10 (DBL_MAX_10_EXP)) but we
30 don't have log10 available in the preprocessor. */
31 # define MAXDIG (DBL_DIG + 3)
34 #define APPEND(a, b) APPEND2 (a, b)
35 #define APPEND2(a, b) a##b
38 #define FCVT_BUFFER APPEND (FUNC_PREFIX, fcvt_buffer)
39 #define ECVT_BUFFER APPEND (FUNC_PREFIX, ecvt_buffer)
42 static char *FCVT_BUFFER
;
43 static char *ECVT_BUFFER
;
47 APPEND (FUNC_PREFIX
, fcvt_allocate
) (void)
49 FCVT_BUFFER
= (char *) malloc (MAXDIG
);
53 APPEND (FUNC_PREFIX
, fcvt
) (value
, ndigit
, decpt
, sign
)
55 int ndigit
, *decpt
, *sign
;
57 __libc_once_define (static, once
);
58 __libc_once (once
, APPEND (FUNC_PREFIX
, fcvt_allocate
));
60 if (FCVT_BUFFER
== NULL
)
61 /* If no core is available we don't have a chance to run the
62 program successfully and so returning NULL is an acceptable
66 (void) APPEND (FUNC_PREFIX
, fcvt_r
) (value
, ndigit
, decpt
, sign
,
74 APPEND (FUNC_PREFIX
, ecvt_allocate
) (void)
76 ECVT_BUFFER
= (char *) malloc (MAXDIG
);
80 APPEND (FUNC_PREFIX
, ecvt
) (value
, ndigit
, decpt
, sign
)
82 int ndigit
, *decpt
, *sign
;
84 __libc_once_define (static, once
);
85 __libc_once (once
, APPEND (FUNC_PREFIX
, ecvt_allocate
));
87 if (ECVT_BUFFER
== NULL
)
88 /* If no core is available we don't have a chance to run the
89 program successfully and so returning NULL is an acceptable
93 (void) APPEND (FUNC_PREFIX
, ecvt_r
) (value
, ndigit
, decpt
, sign
,
100 APPEND (FUNC_PREFIX
, gcvt
) (value
, ndigit
, buf
)
105 sprintf (buf
, "%.*" FLOAT_FMT_FLAG
"g", ndigit
, value
);
110 /* Make sure the memory is freed if the programs ends while in
111 memory-debugging mode and something actually was allocated. */
113 __attribute__ ((unused
))
116 if (FCVT_BUFFER
!= NULL
)
118 if (ECVT_BUFFER
!= NULL
)
122 text_set_element (__libc_subfreeres
, free_mem
);