summaryrefslogtreecommitdiffstats
path: root/contrib/gdtoa/g_dfmt.c
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2009-01-28 04:36:34 +0000
committerdas <das@FreeBSD.org>2009-01-28 04:36:34 +0000
commit1dd1bae7b6975b8f90638d416af36744406345b4 (patch)
treec4d28a7b5d5d1902de89c3a33988ed7f5638277b /contrib/gdtoa/g_dfmt.c
parent0ae48d48ab38ccf64f5cda7e2bc3a30aa4b7c4c2 (diff)
parent5606fb59f1820207cf2c2c8709586e36f114a8f7 (diff)
downloadFreeBSD-src-1dd1bae7b6975b8f90638d416af36744406345b4.zip
FreeBSD-src-1dd1bae7b6975b8f90638d416af36744406345b4.tar.gz
Vendor import of gdtoa 20081205.
Diffstat (limited to 'contrib/gdtoa/g_dfmt.c')
-rw-r--r--contrib/gdtoa/g_dfmt.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/contrib/gdtoa/g_dfmt.c b/contrib/gdtoa/g_dfmt.c
index db2636f..23d8b24 100644
--- a/contrib/gdtoa/g_dfmt.c
+++ b/contrib/gdtoa/g_dfmt.c
@@ -33,15 +33,20 @@ THIS SOFTWARE.
char*
#ifdef KR_headers
-g_dfmt(buf, d, ndig, bufsize) char *buf; double *d; int ndig; unsigned bufsize;
+g_dfmt(buf, d, ndig, bufsize) char *buf; double *d; int ndig; size_t bufsize;
#else
-g_dfmt(char *buf, double *d, int ndig, unsigned bufsize)
+g_dfmt(char *buf, double *d, int ndig, size_t bufsize)
#endif
{
- static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, 0 };
+ static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, 0 };
char *b, *s, *se;
ULong bits[2], *L, sign;
int decpt, ex, i, mode;
+#ifdef Honor_FLT_ROUNDS
+#include "gdtoa_fltrnds.h"
+#else
+#define fpi &fpi0
+#endif
if (ndig < 0)
ndig = 0;
@@ -52,6 +57,8 @@ g_dfmt(char *buf, double *d, int ndig, unsigned bufsize)
sign = L[_0] & 0x80000000L;
if ((L[_0] & 0x7ff00000) == 0x7ff00000) {
/* Infinity or NaN */
+ if (bufsize < 10)
+ return 0;
if (L[_0] & 0xfffff || L[_1]) {
return strcp(buf, "NaN");
}
@@ -78,12 +85,9 @@ g_dfmt(char *buf, double *d, int ndig, unsigned bufsize)
ex = 1;
ex -= 0x3ff + 52;
mode = 2;
- if (ndig <= 0) {
- if (bufsize < 25)
- return 0;
+ if (ndig <= 0)
mode = 0;
- }
i = STRTOG_Normal;
- s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se);
- return g__fmt(buf, s, se, decpt, sign);
+ s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
+ return g__fmt(buf, s, se, decpt, sign, bufsize);
}
OpenPOWER on IntegriCloud