newlib-cygwin/newlib/libc/stdlib/efgcvt.c

169 lines
3.9 KiB
C
Raw Normal View History

2000-02-18 03:39:52 +08:00
/*
FUNCTION
2005-10-28 Bob Wilson <bob.wilson@acm.org> * libc/misc/unctrl.c: Replace FUNCTION description. * libc/signal/signal.c: Remove documentation for raise and _raise_r. * libc/stdio/getdelim.c: Fix spelling errors. * libc/stdio/getw.c: Put RETURNS on a separate line. Fix punctuation. * libc/stdio/putw.c: Likewise. * libc/stdlib/a64l.c: Fix formatting, spelling and punctuation in documentation. * libc/stdlib/assert.c: Do not capitalize FUNCTION description. * libc/stdlib/efgcvt.c: Add spaces to FUNCTION description. * libc/stdlib/envlock.c: Use em-dash in FUNCTION description. * libc/stdlib/mlock.c: Likewise. * libc/stdlib/mstats.c: Likewise. * libc/time/tzlock.c: Likewise. * libc/stdlib/rand.c: Use "multi-threaded" and "thread-safe" in NOTES. * libc/stdlib/rand48.c: Remove extra space in FUNCTION description and hyphenate "pseudo-random". * libc/string/bcmp.c: Remove extra blank lines in documentation. * libc/string/strncat.c: Likewise. * libc/string/memchr.c: Remove extra ">" character in documentation. * libc/string/strcspn.c: Use "characters" instead of "chars". * libc/string/strpbrk.c: Likewise. * libc/string/strerror_r.c: Capitalize "GNU". * libc/string/strnlen.c: Likewise. * libc/string/strtok.c: Fix formatting, spelling and punctuation in documentation. Use "multi-threaded" and "thread-safe" in NOTES. * libc/string/wcscat.c: Split PORTABILITY into two paragraphs. * libc/string/wcschr.c: Likewise. * libc/string/wcscmp.c: Likewise. * libc/string/wcscpy.c: Likewise. * libc/string/wcscspn.c: Likewise. * libc/string/wcslen.c: Likewise. * libc/string/wcsncat.c: Likewise. * libc/string/wcsncmp.c: Likewise. * libc/string/wcsncpy.c: Likewise. * libc/string/wcsnlen.c: Likewise. * libc/string/wcspbrk.c: Likewise. * libc/string/wcsrchr.c: Likewise. * libc/string/wcsspn.c: Likewise. * libc/string/wmemchr.c: Likewise. * libc/string/wmemcmp.c: Likewise. * libc/string/wmemcpy.c: Likewise. * libc/string/wmemset.c: Likewise. * libc/string/wmemmove.c: Likewise. Also fix FUNCTION description. * libc/string/wcswidth.c: Formatting and punctuation in documentation. * libc/string/wcwidth.c: Likewise. * libm/common/s_modf.c: Remove extra period from documentation. * libm/math/s_isnan.c: Fix formatting, grammar and punctuation in documentation. * libm/mathfp/s_isnan.c: Likewise. * libm/math/s_ldexp.c: Fix punctuation. * libm/mathfp/s_ldexp.c: Likewise. * libm/math/w_log.c: Likewise. * libm/mathfp/s_logarithm.c: Likewise. * libm/math/w_j0.c: Add spaces to FUNCTION description. * libm/mathfp/w_jn.c: Likewise.
2005-10-29 05:21:08 +08:00
<<ecvt>>, <<ecvtf>>, <<fcvt>>, <<fcvtf>>---double or float to string
2000-02-18 03:39:52 +08:00
INDEX
ecvt
INDEX
ecvtf
2000-02-18 03:39:52 +08:00
INDEX
fcvt
INDEX
fcvtf
2000-02-18 03:39:52 +08:00
SYNOPSIS
2000-02-18 03:39:52 +08:00
#include <stdlib.h>
char *ecvt(double <[val]>, int <[chars]>, int *<[decpt]>, int *<[sgn]>);
char *ecvtf(float <[val]>, int <[chars]>, int *<[decpt]>, int *<[sgn]>);
char *fcvt(double <[val]>, int <[decimals]>,
int *<[decpt]>, int *<[sgn]>);
char *fcvtf(float <[val]>, int <[decimals]>,
int *<[decpt]>, int *<[sgn]>);
DESCRIPTION
<<ecvt>> and <<fcvt>> produce (null-terminated) strings of digits
representating the <<double>> number <[val]>.
<<ecvtf>> and <<fcvtf>> produce the corresponding character
representations of <<float>> numbers.
(The <<stdlib>> functions <<ecvtbuf>> and <<fcvtbuf>> are reentrant
versions of <<ecvt>> and <<fcvt>>.)
The only difference between <<ecvt>> and <<fcvt>> is the
interpretation of the second argument (<[chars]> or <[decimals]>).
For <<ecvt>>, the second argument <[chars]> specifies the total number
of characters to write (which is also the number of significant digits
in the formatted string, since these two functions write only digits).
For <<fcvt>>, the second argument <[decimals]> specifies the number of
characters to write after the decimal point; all digits for the integer
part of <[val]> are always included.
Since <<ecvt>> and <<fcvt>> write only digits in the output string,
they record the location of the decimal point in <<*<[decpt]>>>, and
the sign of the number in <<*<[sgn]>>>. After formatting a number,
<<*<[decpt]>>> contains the number of digits to the left of the
decimal point. <<*<[sgn]>>> contains <<0>> if the number is positive,
and <<1>> if it is negative.
RETURNS
All four functions return a pointer to the new string containing a
character representation of <[val]>.
PORTABILITY
None of these functions are ANSI C.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
NEWPAGE
FUNCTION
<<gcvt>>, <<gcvtf>>---format double or float as string
2000-02-18 03:39:52 +08:00
INDEX
gcvt
INDEX
gcvtf
SYNOPSIS
2000-02-18 03:39:52 +08:00
#include <stdlib.h>
char *gcvt(double <[val]>, int <[precision]>, char *<[buf]>);
char *gcvtf(float <[val]>, int <[precision]>, char *<[buf]>);
DESCRIPTION
<<gcvt>> writes a fully formatted number as a null-terminated
string in the buffer <<*<[buf]>>>. <<gcvtf>> produces corresponding
2000-02-18 03:39:52 +08:00
character representations of <<float>> numbers.
<<gcvt>> uses the same rules as the <<printf>> format
`<<%.<[precision]>g>>'---only negative values are signed (with
`<<->>'), and either exponential or ordinary decimal-fraction format
is chosen depending on the number of significant digits (specified by
<[precision]>).
RETURNS
The result is a pointer to the formatted representation of <[val]>
(the same as the argument <[buf]>).
PORTABILITY
Neither function is ANSI C.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#define _XOPEN_SOURCE
#define _XOPEN_SOURCE_EXTENDED
2000-02-18 03:39:52 +08:00
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <stdlib.h>
#include "local.h"
2019-07-23 20:15:48 +08:00
char * ecvtbuf (double, int, int*, int*, char *);
char * fcvtbuf (double, int, int*, int*, char *);
2000-02-18 03:39:52 +08:00
char *
fcvt (double d,
int ndigit,
int *decpt,
2000-02-18 03:39:52 +08:00
int *sign)
{
return fcvtbuf (d, ndigit, decpt, sign, NULL);
}
char *
fcvtf (float d,
int ndigit,
int *decpt,
2000-02-18 03:39:52 +08:00
int *sign)
{
return fcvt ((float) d, ndigit, decpt, sign);
}
2019-07-23 20:15:48 +08:00
char *
gcvt (double d,
int ndigit,
char *buf)
{
char *tbuf = buf;
if (d < 0) {
*buf = '-';
buf++;
ndigit--;
}
return (_gcvt (_REENT, d, ndigit, buf, 'g', 0) ? tbuf : 0);
}
2000-02-18 03:39:52 +08:00
char *
gcvtf (float d,
int ndigit,
2000-02-18 03:39:52 +08:00
char *buf)
{
double asd = d;
return gcvt (asd, ndigit, buf);
}
char *
ecvt (double d,
int ndigit,
int *decpt,
2000-02-18 03:39:52 +08:00
int *sign)
{
return ecvtbuf (d, ndigit, decpt, sign, NULL);
}
char *
ecvtf (float d,
int ndigit,
int *decpt,
2000-02-18 03:39:52 +08:00
int *sign)
{
return ecvt ((double) d, ndigit, decpt, sign);
}