1 /* [efg]cvt -- compatibility functions for floating point formatting,
3 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If
18 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
29 #define FLOAT_TYPE double
31 #define FLOAT_FMT_FLAG
32 #define FLOAT_NAME_EXT
35 #define APPEND(a, b) APPEND2 (a, b)
36 #define APPEND2(a, b) a##b
38 #define FLOOR APPEND(floor, FLOAT_NAME_EXT)
39 #define FABS APPEND(fabs, FLOAT_NAME_EXT)
40 #define LOG10 APPEND(log10, FLOAT_NAME_EXT)
44 APPEND (FUNC_PREFIX
, fcvt_r
) (value
, ndigit
, decpt
, sign
, buf
, len
)
46 int ndigit
, *decpt
, *sign
;
62 n
= snprintf (buf
, len
, "%.*" FLOAT_FMT_FLAG
"f", ndigit
, value
);
67 while (i
< n
&& isdigit (buf
[i
]))
72 while (! isdigit (buf
[i
]));
73 memmove (&buf
[i
- *decpt
], buf
, n
- (i
- *decpt
));
78 #define weak_extern2(name) weak_extern (name)
79 weak_extern2 (FLOOR
) weak_extern2 (LOG10
) weak_extern2 (FABS
)
82 APPEND (FUNC_PREFIX
, ecvt_r
) (value
, ndigit
, decpt
, sign
, buf
, len
)
84 int ndigit
, *decpt
, *sign
;
88 FLOAT_TYPE (*log10_function
) (FLOAT_TYPE
) = &LOG10
;
92 /* Use the reasonable code if -lm is included. */
93 ndigit
-= (int) FLOOR (LOG10 (FABS (value
)));
99 /* Slow code that doesn't require -lm functions. */
101 for (d
= value
< 0.0 ? - value
: value
;
102 ndigit
> 0 && d
>= 10.0;
107 return APPEND (FUNC_PREFIX
, fcvt_r
) (value
, ndigit
, decpt
, sign
, buf
, len
);