Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/gdtoa from www.netlib.org
details: https://anonhg.NetBSD.org/src/rev/67a1215b2285
branches: trunk
changeset: 763436:67a1215b2285
user: christos <christos%NetBSD.org@localhost>
date: Sat Mar 19 16:26:36 2011 +0000
description:
from www.netlib.org
diffstat:
lib/libc/gdtoa/README | 32 +-
lib/libc/gdtoa/g__fmt.c | 72 +-
lib/libc/gdtoa/gdtoa_fltrnds.h | 18 +
lib/libc/gdtoa/printf.c | 8 +
lib/libc/gdtoa/printf.c0 | 1669 ++++++++++++++++++++++++++++++++++
lib/libc/gdtoa/stdio1.h | 103 ++
lib/libc/gdtoa/test/Q.ou0 | 1180 ++++++++++++++++++++++++
lib/libc/gdtoa/test/Q.ou1 | 1468 +++++++++++++++++++++++++++++
lib/libc/gdtoa/test/Qtest.c | 178 +++
lib/libc/gdtoa/test/README | 81 +
lib/libc/gdtoa/test/d.out | 986 ++++++++++++++++++++
lib/libc/gdtoa/test/dI.out | 168 +++
lib/libc/gdtoa/test/dIsi.out | 168 +++
lib/libc/gdtoa/test/dItest.c | 82 +
lib/libc/gdtoa/test/dd.out | 1356 +++++++++++++++++++++++++++
lib/libc/gdtoa/test/ddsi.out | 376 +++++++
lib/libc/gdtoa/test/ddtest.c | 177 +++
lib/libc/gdtoa/test/dt.c | 291 +++++
lib/libc/gdtoa/test/dtest.c | 139 ++
lib/libc/gdtoa/test/dtst.out | 684 +++++++++++++
lib/libc/gdtoa/test/f.out | 988 ++++++++++++++++++++
lib/libc/gdtoa/test/ftest.c | 140 ++
lib/libc/gdtoa/test/getround.c | 90 +
lib/libc/gdtoa/test/makefile | 172 +++
lib/libc/gdtoa/test/obad/strtodt.out | 6 +
lib/libc/gdtoa/test/obad/xL.out | 1460 +++++++++++++++++++++++++++++
lib/libc/gdtoa/test/pfLqtestnos | 13 +
lib/libc/gdtoa/test/pftest.c | 158 +++
lib/libc/gdtoa/test/pftestLq.out | 13 +
lib/libc/gdtoa/test/pftestQ.out | 15 +
lib/libc/gdtoa/test/pftestnos | 15 +
lib/libc/gdtoa/test/pftestx.out | 15 +
lib/libc/gdtoa/test/rtestnos | 76 +
lib/libc/gdtoa/test/strtoIdSI.c | 2 +
lib/libc/gdtoa/test/strtoIddSI.c | 2 +
lib/libc/gdtoa/test/strtodISI.c | 2 +
lib/libc/gdtoa/test/strtodt.c | 138 ++
lib/libc/gdtoa/test/strtopddSI.c | 2 +
lib/libc/gdtoa/test/strtorddSI.c | 2 +
lib/libc/gdtoa/test/testnos | 28 +
lib/libc/gdtoa/test/testnos1 | 20 +
lib/libc/gdtoa/test/testnos3 | 352 +++++++
lib/libc/gdtoa/test/x.ou0 | 1182 ++++++++++++++++++++++++
lib/libc/gdtoa/test/x.ou1 | 1460 +++++++++++++++++++++++++++++
lib/libc/gdtoa/test/xL.ou0 | 1182 ++++++++++++++++++++++++
lib/libc/gdtoa/test/xL.ou1 | 1462 +++++++++++++++++++++++++++++
lib/libc/gdtoa/test/xLtest.c | 169 +++
lib/libc/gdtoa/test/xQtest.c | 58 +
lib/libc/gdtoa/test/xsum0.out | 41 +
lib/libc/gdtoa/test/xtest.c | 170 +++
lib/libc/gdtoa/xsum0.out | 70 +-
51 files changed, 18690 insertions(+), 49 deletions(-)
diffs (truncated from 19028 to 300 lines):
diff -r ae5dd709e4ec -r 67a1215b2285 lib/libc/gdtoa/README
--- a/lib/libc/gdtoa/README Sat Mar 19 16:10:16 2011 +0000
+++ b/lib/libc/gdtoa/README Sat Mar 19 16:26:36 2011 +0000
@@ -1,5 +1,3 @@
-$NetBSD: README,v 1.1.1.1 2006/01/25 15:18:40 kleink Exp $
-
This directory contains source for a library of binary -> decimal
and decimal -> binary conversion routines, for single-, double-,
and extended-precision IEEE binary floating-point arithmetic, and
@@ -58,7 +56,9 @@
whose sum is the desired value
For decimal -> binary conversions, there are three families of
-helper routines: one for round-nearest:
+helper routines: one for round-nearest (or the current rounding
+mode on IEEE-arithmetic systems that provide the C99 fegetround()
+function, if compiled with -DHonor_FLT_ROUNDS):
strtof
strtod
@@ -193,6 +193,9 @@
conversion are easily done with the help of gdtoa(), such as %e or %f
style and conversions with direction of rounding specified (so that, if
desired, the decimal value is either >= or <= the binary value).
+On IEEE-arithmetic systems that provide the C99 fegetround() function,
+if compiled with -DHonor_FLT_ROUNDS, these routines honor the current
+rounding mode.
For an example of more general conversions based on dtoa(), see
netlib's "printf.c from ampl/solvers".
@@ -334,5 +337,28 @@
the decimal-point character to be taken from the current locale; otherwise
it is '.'.
+Source files dtoa.c and strtod.c in this directory are derived from
+netlib's "dtoa.c from fp" and are meant to function equivalently.
+When compiled with Honor_FLT_ROUNDS #defined (on systems that provide
+FLT_ROUNDS and fegetround() as specified in the C99 standard), they
+honor the current rounding mode. Because FLT_ROUNDS is buggy on some
+(Linux) systems -- not reflecting calls on fesetround(), as the C99
+standard says it should -- when Honor_FLT_ROUNDS is #defined, the
+current rounding mode is obtained from fegetround() rather than from
+FLT_ROUNDS, unless Trust_FLT_ROUNDS is also #defined.
+
+Compile with -DUSE_LOCALE to use the current locale; otherwise
+decimal points are assumed to be '.'. With -DUSE_LOCALE, unless
+you also compile with -DNO_LOCALE_CACHE, the details about the
+current "decimal point" character string are cached and assumed not
+to change during the program's execution.
+
+On machines with a 64-bit long double and perhaps a 113-bit "quad"
+type, you can invoke "make Printf" to add Printf (and variants, such
+as Fprintf) to gdtoa.a. These are analogs, declared in stdio1.h, of
+printf and fprintf, etc. in which %La, %Le, %Lf, and %Lg are for long
+double and (if appropriate) %Lqa, %Lqe, %Lqf, and %Lqg are for quad
+precision printing.
+
Please send comments to David M. Gay (dmg at acm dot org, with " at "
changed at "@" and " dot " changed to ".").
diff -r ae5dd709e4ec -r 67a1215b2285 lib/libc/gdtoa/g__fmt.c
--- a/lib/libc/gdtoa/g__fmt.c Sat Mar 19 16:10:16 2011 +0000
+++ b/lib/libc/gdtoa/g__fmt.c Sat Mar 19 16:26:36 2011 +0000
@@ -1,5 +1,3 @@
-/* $NetBSD: g__fmt.c,v 1.1.1.1 2006/01/25 15:18:41 kleink Exp $ */
-
/****************************************************************
The author of this software is David M. Gay.
@@ -39,24 +37,51 @@
char *
#ifdef KR_headers
-g__fmt(b, s, se, decpt, sign) char *b; char *s; char *se; int decpt; ULong sign;
+g__fmt(b, s, se, decpt, sign, blen) char *b; char *s; char *se; int decpt; ULong sign; size_t blen;
#else
-g__fmt(char *b, char *s, char *se, int decpt, ULong sign)
+g__fmt(char *b, char *s, char *se, int decpt, ULong sign, size_t blen)
#endif
{
int i, j, k;
- char *s0 = s;
+ char *be, *s0;
+ size_t len;
#ifdef USE_LOCALE
- char decimalpoint = *localeconv()->decimal_point;
+#ifdef NO_LOCALE_CACHE
+ char *decimalpoint = localeconv()->decimal_point;
+ size_t dlen = strlen(decimalpoint);
#else
-#define decimalpoint '.'
+ char *decimalpoint;
+ static char *decimalpoint_cache;
+ static size_t dlen;
+ if (!(s0 = decimalpoint_cache)) {
+ s0 = localeconv()->decimal_point;
+ dlen = strlen(s0);
+ if ((decimalpoint_cache = (char*)MALLOC(strlen(s0) + 1))) {
+ strcpy(decimalpoint_cache, s0);
+ s0 = decimalpoint_cache;
+ }
+ }
+ decimalpoint = s0;
#endif
+#else
+#define dlen 0
+#endif
+ s0 = s;
+ len = (se-s) + dlen + 6; /* 6 = sign + e+dd + trailing null */
+ if (blen < len)
+ goto ret0;
+ be = b + blen - 1;
if (sign)
*b++ = '-';
if (decpt <= -4 || decpt > se - s + 5) {
*b++ = *s++;
if (*s) {
- *b++ = decimalpoint;
+#ifdef USE_LOCALE
+ while((*b = *decimalpoint++))
+ ++b;
+#else
+ *b++ = '.';
+#endif
while((*b = *s++) !=0)
b++;
}
@@ -71,6 +96,8 @@
for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10){}
for(;;) {
i = decpt / k;
+ if (b >= be)
+ goto ret0;
*b++ = i + '0';
if (--j <= 0)
break;
@@ -80,22 +107,41 @@
*b = 0;
}
else if (decpt <= 0) {
- *b++ = decimalpoint;
+#ifdef USE_LOCALE
+ while((*b = *decimalpoint++))
+ ++b;
+#else
+ *b++ = '.';
+#endif
+ if (be < b - decpt + (se - s))
+ goto ret0;
for(; decpt < 0; decpt++)
*b++ = '0';
- while((*b = *s++) !=0)
+ while((*b = *s++) != 0)
b++;
}
else {
- while((*b = *s++) !=0) {
+ while((*b = *s++) != 0) {
b++;
- if (--decpt == 0 && *s)
- *b++ = decimalpoint;
+ if (--decpt == 0 && *s) {
+#ifdef USE_LOCALE
+ while(*b = *decimalpoint++)
+ ++b;
+#else
+ *b++ = '.';
+#endif
+ }
+ }
+ if (b + decpt > be) {
+ ret0:
+ b = 0;
+ goto ret;
}
for(; decpt > 0; decpt--)
*b++ = '0';
*b = 0;
}
+ ret:
freedtoa(s0);
return b;
}
diff -r ae5dd709e4ec -r 67a1215b2285 lib/libc/gdtoa/gdtoa_fltrnds.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/gdtoa/gdtoa_fltrnds.h Sat Mar 19 16:26:36 2011 +0000
@@ -0,0 +1,18 @@
+ FPI *fpi, fpi1;
+ int Rounding;
+#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */
+ Rounding = Flt_Rounds;
+#else /*}{*/
+ Rounding = 1;
+ switch(fegetround()) {
+ case FE_TOWARDZERO: Rounding = 0; break;
+ case FE_UPWARD: Rounding = 2; break;
+ case FE_DOWNWARD: Rounding = 3;
+ }
+#endif /*}}*/
+ fpi = &fpi0;
+ if (Rounding != 1) {
+ fpi1 = fpi0;
+ fpi = &fpi1;
+ fpi1.rounding = Rounding;
+ }
diff -r ae5dd709e4ec -r 67a1215b2285 lib/libc/gdtoa/printf.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/gdtoa/printf.c Sat Mar 19 16:26:36 2011 +0000
@@ -0,0 +1,8 @@
+#ifdef __sun
+#define Use_GDTOA_Qtype
+#else
+#if defined(__i386) || defined(__x86_64)
+#define Use_GDTOA_for_i386_long_double
+#endif
+#endif
+#include "printf.c0"
diff -r ae5dd709e4ec -r 67a1215b2285 lib/libc/gdtoa/printf.c0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/gdtoa/printf.c0 Sat Mar 19 16:26:36 2011 +0000
@@ -0,0 +1,1669 @@
+/****************************************************************
+Copyright (C) 1997, 1999, 2001 Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+****************************************************************/
+
+/* This implements most of ANSI C's printf, fprintf, and sprintf,
+ * omitting L, with %.0g and %.0G giving the shortest decimal string
+ * that rounds to the number being converted, and with negative
+ * precisions allowed for %f.
+ */
+
+#ifdef KR_headers
+#include "varargs.h"
+#else
+#include "stddef.h"
+#include "stdarg.h"
+#include "stdlib.h"
+#endif
+
+#ifdef Use_GDTOA_for_i386_long_double /*{{*/
+#include "gdtoa.h"
+#else /*}{*/
+#ifndef NO_PRINTF_A_FMT /*{*/
+#include "gdtoa.h"
+#endif /*}*/
+#endif /*}}*/
+
+#ifdef __i386
+#define NO_GDTOA_i386_Quad
+#endif
+
+#ifdef Use_GDTOA_for_i386_long_double /*{*/
+#ifndef NO_GDTOA_i386_Quad /*{*/
+#define GDTOA_both
+#define Use_GDTOA_Qtype
+#ifdef __ICC__ /* or __INTEL_COMPILER__ or __INTEL_COMPILER ?? */
+#define GDTOA_Qtype _Quad
+#else
+#define GDTOA_Qtype __float128
+#endif
+#endif /*} NO_GDTOA_i386_Quad */
+#endif /*} Use_GDTOA_for_i386_long_double */
+
+#ifdef Use_GDTOA_Qtype /*{*/
+#ifndef GDTOA_H_INCLUDED
+#include "gdtoa.h"
+#endif
+#ifndef GDTOA_Qtype
+#define GDTOA_Qtype long double
+#endif
+#endif /*}*/
+
+#ifndef GDTOA_H_INCLUDED /*{*/
+
+ enum { /* return values from strtodg */
+ STRTOG_Zero = 0,
+ STRTOG_Normal = 1,
+ STRTOG_Denormal = 2,
+ STRTOG_Infinite = 3,
+ STRTOG_NaN = 4,
+ STRTOG_NaNbits = 5,
Home |
Main Index |
Thread Index |
Old Index