summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2006-01-10 16:18:38 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2006-01-10 16:18:38 +0000
commit947402472b84531c22b25222f91111e9aa2952b5 (patch)
tree2fdadff80fcf222f9721039e06e55b4e6202a0cc /lib/libc/stdlib
parent979d35bc27826ea04c42887dd10973449c449bd0 (diff)
Return inf or nan as per printf() not Inf, Infinity or Nan (from dtoa)
Remove an extraneous check for dtoa returning Inf/Nan
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/ecvt.c14
-rw-r--r--lib/libc/stdlib/gcvt.c12
2 files changed, 15 insertions, 11 deletions
diff --git a/lib/libc/stdlib/ecvt.c b/lib/libc/stdlib/ecvt.c
index 9289b3bf8a1..eb0e4289966 100644
--- a/lib/libc/stdlib/ecvt.c
+++ b/lib/libc/stdlib/ecvt.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: ecvt.c,v 1.4 2005/08/08 08:05:36 espie Exp $ */
+/* $OpenBSD: ecvt.c,v 1.5 2006/01/10 16:18:37 millert Exp $ */
/*
- * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2002, 2006 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -62,11 +62,11 @@ __cvt(double value, int ndigit, int *decpt, int *sign, int fmode, int pad)
} else {
p = __dtoa(value, fmode + 2, ndigit, decpt, sign, &rve);
if (*decpt == 9999) {
- /* Nan or Infinity */
+ /* Infinity or Nan, convert to inf or nan like printf */
*decpt = 0;
- return(p);
+ return(*p == 'I' ? "inf" : "nan");
}
- /* make a local copy and adjust rve to be in terms of s */
+ /* Make a local copy and adjust rve to be in terms of s */
if (pad && fmode)
siz += *decpt;
if ((s = (char *)malloc(siz)) == NULL)
@@ -75,8 +75,8 @@ __cvt(double value, int ndigit, int *decpt, int *sign, int fmode, int pad)
rve = s + (rve - p);
}
- /* Add trailing zeros (unless we got NaN or Inf) */
- if (pad && *decpt != 9999) {
+ /* Add trailing zeros */
+ if (pad) {
siz -= rve - s;
while (--siz)
*rve++ = '0';
diff --git a/lib/libc/stdlib/gcvt.c b/lib/libc/stdlib/gcvt.c
index 9ba932e1237..bc6295c03de 100644
--- a/lib/libc/stdlib/gcvt.c
+++ b/lib/libc/stdlib/gcvt.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: gcvt.c,v 1.8 2006/01/10 02:23:02 millert Exp $ */
+/* $OpenBSD: gcvt.c,v 1.9 2006/01/10 16:18:37 millert Exp $ */
/*
- * Copyright (c) 2002, 2003 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2002, 2003, 2006 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -42,8 +42,12 @@ gcvt(double value, int ndigit, char *buf)
digits = __dtoa(value, 2, ndigit, &decpt, &sign, NULL);
if (decpt == 9999) {
- /* Infinity or NaN, assume buffer is at least ndigit long. */
- snprintf(buf, ndigit + 1, "%s%s", sign ? "-" : "", digits);
+ /*
+ * Infinity or NaN, convert to inf or nan with sign.
+ * We assume the buffer is at least ndigit long.
+ */
+ snprintf(buf, ndigit + 1, "%s%s", sign ? "-" : "",
+ *digits == 'I' ? "inf" : "nan");
return (buf);
}