[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commits] r16626 - in /libdfp/trunk: ./ dfp/ dfp/decimal/ tests/
- To: commits@xxxxxxxxxx
- Subject: [Commits] r16626 - in /libdfp/trunk: ./ dfp/ dfp/decimal/ tests/
- From: ryanarn@xxxxxxxxxx
- Date: Tue, 10 Jan 2012 18:31:53 -0000
Author: ryanarn
Date: Tue Jan 10 18:31:52 2012
New Revision: 16626
Log:
Completed support for C++ decimal[32|64|128] types operator<< and operator>>.
Also added dpf/float.h to define C++ -> C compatibility types
_Decimal[32|64|128].
2012-01-10 Ryan S. Arnold <rsa@xxxxxxxxxxxxxxxxxx>
* Makefile.in (libdfp_cxx_tests): Added test-istream.
* tests/scaffold.c (_ISC _ISC_P): Added new istream compare macros
conditional on #ifdef __cplusplus.
* tests/test-istream.cpp: New test for operator>>.
* tests/test-strtod.c: Added a new value to test.
* dfp/float.h: Correct _Decimal[32|64|128] declarations.
* dfp/decimal/decimal: Added operator>> support for decimal[32|64|128]
C++ decimal floating point types.
* README.user: Updated information on operator<< and operator>>
support.
Added:
libdfp/trunk/tests/test-istream.cpp
Modified:
libdfp/trunk/ChangeLog
libdfp/trunk/Makefile.in
libdfp/trunk/README.user
libdfp/trunk/dfp/decimal/decimal
libdfp/trunk/dfp/float.h
libdfp/trunk/tests/scaffold.c
libdfp/trunk/tests/test-strtod.c
Modified: libdfp/trunk/ChangeLog
==============================================================================
--- libdfp/trunk/ChangeLog (original)
+++ libdfp/trunk/ChangeLog Tue Jan 10 18:31:52 2012
@@ -1,3 +1,16 @@
+2012-01-10 Ryan S. Arnold <rsa@xxxxxxxxxxxxxxxxxx>
+
+ * Makefile.in (libdfp_cxx_tests): Added test-istream.
+ * tests/scaffold.c (_ISC _ISC_P): Added new istream compare macros
+ conditional on #ifdef __cplusplus.
+ * tests/test-istream.cpp: New test for operator>>.
+ * tests/test-strtod.c: Added a new value to test.
+ * dfp/float.h: Correct _Decimal[32|64|128] declarations.
+ * dfp/decimal/decimal: Added operator>> support for decimal[32|64|128]
+ C++ decimal floating point types.
+ * README.user: Updated information on operator<< and operator>>
+ support.
+
2011-12-14 Ryan S. Arnold <rsa@xxxxxxxxxxxxxxxxxx>
* tests/test-log10d.c: Added missing #include "decode.h".
Modified: libdfp/trunk/Makefile.in
==============================================================================
--- libdfp/trunk/Makefile.in (original)
+++ libdfp/trunk/Makefile.in Tue Jan 10 18:31:52 2012
@@ -330,7 +330,7 @@
test-round test-bfp-conversions test-stdlib test-wchar \
test-expd
-libdfp_cxx_tests = test-ostream
+libdfp_cxx_tests = test-ostream test-istream
libdfp_tests = $(libdfp_c_tests) $(libdfp_cxx_tests)
Modified: libdfp/trunk/README.user
==============================================================================
--- libdfp/trunk/README.user (original)
+++ libdfp/trunk/README.user Tue Jan 10 18:31:52 2012
@@ -4,7 +4,7 @@
The "Decimal Floating Point C Library" User's Guide
for the GNU/Linux OS and GLIBC 2.10+
Contributed by IBM Corporation
- Copyright (C) 2010 Free Software Foundation
+ Copyright (C) 2010 - 2012 Free Software Foundation
===========================================================================
NOTE:Eight space tabs are the optimum editor setting for reading this file.
@@ -12,7 +12,7 @@
Author(s) : Ryan S. Arnold <rsa@xxxxxxxxxx>
Date Created: January 27, 2010
- Last Changed: December 5, 2011
+ Last Changed: January 10, 2012
---------------------------------------------------------------------------
Table of Contents:
@@ -34,7 +34,7 @@
4.3 GCC With --enable-decimal-float Support
5. _Decimal* Data Types
5.1 C++ decimal[32|64|128] Types Compatibility
- 5.2 C++ decimal[32|64|128] operator<< and operator>> Overloads
+ 5.2 C++ decimal[32|64|128] operator<< and operator>> Support
6. DFP Headers
7. Compile and Link
8. Unsupported/Non-Standard Additions
@@ -280,10 +280,10 @@
of convenience, libdfp has provided these headers in the libdfp headers
directory include/dfp/float.h
-5.2 C++ decimal[32|64|128] operator<< and operator>> Overloads
----------------------------------------------------------------------------
-
-Your C++ compiler may not provide the operator<< and operator>> overloads
+5.2 C++ decimal[32|64|128] operator<< and operator>> Support
+---------------------------------------------------------------------------
+
+Your C++ compiler may not provide operator<< and operator>> support
for std::decimal::decimal[32|64|128] data types. Per the C++ DFP
specification: ISO/IEC JTC1 SC22 WG21 N2732 "Extension for the programming
language C++ to support decimal floating point arithmetic", the header
Modified: libdfp/trunk/dfp/decimal/decimal
==============================================================================
--- libdfp/trunk/dfp/decimal/decimal (original)
+++ libdfp/trunk/dfp/decimal/decimal Tue Jan 10 18:31:52 2012
@@ -1,6 +1,6 @@
/* <decimal> for libdfp and redirect to system <decimal>
- Copyright (C) 2011 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the Decimal Floating Point C Library.
@@ -40,6 +40,9 @@
#include <ostream>
using std::ostream;
+
+#include <istream>
+using std::istream;
/* Per ISO/IEC JTC1 SC22 WG21 N2732 - TR 24733: "Extension for the programming
* language C++ to support decimal floating point arithmetic" define the
@@ -156,6 +159,14 @@
enum {DEC_MANT_DIG = FIND_DEC_MANT_DIG<(sizeof(decimal_type))>::RESULT};
};
+#include <stdlib.h> /* Pick up the strtod* prototypes */
+
+#include <limits.h> /* For CHAR_MAX */
+
+#include <istream>
+
+#include <string.h> /* For memset */
+
namespace std
{
namespace decimal
@@ -196,17 +207,39 @@
}
// ISO/IEC TR 27433 - 3.2.11 Formatted input:
-// template <class charT, class traits>
-// std::basic_istream<charT, traits> &
-// operator>>(std::basic_istream<charT, traits> & is, decimal32 & d);
-
-// template <class charT, class traits>
-// std::basic_istream<charT, traits> &
-// operator>>(std::basic_istream<charT, traits> & is, decimal64 & d);
-
-// template <class charT, class traits>
-// std::basic_istream<charT, traits> &
-// operator>>(std::basic_istream<charT, traits> & is, decimal128 & d);
+
+ template <class charT, class traits>
+ inline std::basic_istream<charT, traits> &
+ operator>>(std::basic_istream<charT, traits> & is, decimal32 & d)
+ {
+ char buf[CHAR_MAX];
+ memset(buf, '\0', CHAR_MAX);
+ is.read(buf,CHAR_MAX);
+ d.__setval(strtod32(buf, NULL));
+ return is;
+ }
+
+ template <class charT, class traits>
+ inline std::basic_istream<charT, traits> &
+ operator>>(std::basic_istream<charT, traits> & is, decimal64 & d)
+ {
+ char buf[CHAR_MAX];
+ memset(buf, '\0', CHAR_MAX);
+ is.read(buf,CHAR_MAX);
+ d.__setval(strtod64(buf, NULL));
+ return is;
+ }
+
+ template <class charT, class traits>
+ inline std::basic_istream<charT, traits> &
+ operator>>(std::basic_istream<charT, traits> & is, decimal128 & d)
+ {
+ char buf[CHAR_MAX];
+ memset(buf, '\0', CHAR_MAX);
+ is.read(buf,CHAR_MAX);
+ d.__setval(strtod128(buf, NULL));
+ return is;
+ }
} /* namespace decimal */
} /* namespace std */
Modified: libdfp/trunk/dfp/float.h
==============================================================================
--- libdfp/trunk/dfp/float.h (original)
+++ libdfp/trunk/dfp/float.h Tue Jan 10 18:31:52 2012
@@ -1,6 +1,6 @@
/* <float.h> for libdfp and redirect to system <float.h>
- Copyright (C) 2011 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This file is part of the Decimal Floating Point C Library.
@@ -36,18 +36,23 @@
#ifndef _Decimal64
/* Predeclare the decimal classes so we can typedef without errors. */
-namespace std { namespace decimal { class decimal32; }; };
-namespace std { namespace decimal { class decimal64; }; };
-namespace std { namespace decimal { class decimal128; }; };
+//namespace std { namespace decimal { class decimal32; }; };
+//namespace std { namespace decimal { class decimal64; }; };
+//namespace std { namespace decimal { class decimal128; }; };
/* Per ISO/IEC TR 24733 the following typedefs SHOULD be defined in float.h
- * but depending on the compiler version they may NOT be, so we'll define them
- * as a service if they are not defined in the system float.h. */
+*
+ * typedef std::decimal::decimal32 _Decimal32;
+ * typedef std::decimal::decimal64 _Decimal64;
+ * typedef std::decimal::decimal128 _Decimal128;
+ *
+ * Depending on the compiler version they may NOT be, so we'll define them
+ * as a service if they are not defined in the system float.h.
+ */
-typedef std::decimal::decimal32 _Decimal32;
-typedef std::decimal::decimal64 _Decimal64;
-typedef std::decimal::decimal128 _Decimal128;
-
+typedef float _Decimal32 __attribute__((mode(SD)));
+typedef float _Decimal64 __attribute__((mode(DD)));
+typedef float _Decimal128 __attribute__((mode(TD)));
#endif /* _Decimal64 */
#endif /* __cplusplus */
#endif /* _LIBDFP_FLOAT_H */
Modified: libdfp/trunk/tests/scaffold.c
==============================================================================
--- libdfp/trunk/tests/scaffold.c (original)
+++ libdfp/trunk/tests/scaffold.c Tue Jan 10 18:31:52 2012
@@ -1,6 +1,6 @@
/* Test facility scaffolding.
- Copyright (C) 2009, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2011, 2011 Free Software Foundation, Inc.
This file is part of the Decimal Floating Point C Library.
@@ -105,6 +105,46 @@
#endif /* _OSC */
#endif /* __cplusplus */
#endif /* _WANT_OSC */
+
+#ifdef _WANT_ISC
+#ifndef __cplusplus
+#warning "_WANT_ISC only available #ifdef __cplusplus. _ISC and _ISC_P use <sstream>."
+#else /* __cplusplus */
+#ifndef _ISC
+#include <sstream>
+#define _WANT_VC 1
+
+#define _ISC_P(f,l,x,y,z,fmt) do { \
+ std::stringstream s; \
+ /* Clear the stringstream. */ \
+ s.str(std::string()); \
+ /* Push the string to test onto the stream. */ \
+ s << y; \
+ /* invoke operator>>(istream &,decimal[32|64|128] &) */ \
+ s >> z; \
+ _VC_P(f,l,x,z,fmt); \
+} while(0)
+
+/* _ISC == Istream Compare
+ *
+ * Macro used to compare an istream (operator>>) invocation with an expected
+ * result.
+ *
+ * X: Expected decimal[32|64|128] value
+ * Y: Input string
+ * Z: Input temp decimal[32|64|128] used to store the result
+ * fmt: format string for the decimal type.
+ * e.g.
+ * _ISC("-0.009999",-9.999E-3DD,z,fmt);
+ *
+ * Equivalent to the following example:
+ *
+ */
+#define _ISC(x,y,z,fmt) _ISC_P (__FILE__,__LINE__,x,y,z,fmt)
+#endif /* _ISC */
+#endif /* __cplusplus */
+#endif /* _WANT_ISC */
+
#ifdef _WANT_PC
static char buf[CHAR_MAX];
Added: libdfp/trunk/tests/test-istream.cpp
==============================================================================
--- libdfp/trunk/tests/test-istream.cpp (added)
+++ libdfp/trunk/tests/test-istream.cpp Tue Jan 10 18:31:52 2012
@@ -1,0 +1,131 @@
+/* Test istream operator in cpp compat header <dfp/decimal/decimal>.
+
+ Copyright (C) 2012 Free Software Foundation, Inc.
+
+ This file is part of the Decimal Floating Point C Library.
+
+ Author(s): Ryan S. Arnold <rsa@xxxxxxxxxx>
+
+ The Decimal Floating Point C Library is free software; you can
+ redistribute it and/or modify it under the terms of the GNU Lesser
+ General Public License version 2.1.
+
+ The Decimal Floating Point C Library is distributed in the hope that
+ it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ the GNU Lesser General Public License version 2.1 for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License version 2.1 along with the Decimal Floating Point C Library;
+ if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ Suite 330, Boston, MA 02111-1307 USA.
+
+ Please see libdfp/COPYING.txt for more information. */
+
+#ifndef __STDC_WANT_DEC_FP__
+#define __STDC_WANT_DEC_FP__
+#endif
+
+/* This is a CPP compatibility testcase. Pick up the _Decimal[32|64|128]
+ * definitions. */
+#include <float.h>
+
+#include <decimal/decimal>
+
+#include <iomanip>
+
+/* For cout support. */
+#include <iostream>
+
+using namespace std;
+using namespace std::decimal;
+
+ /* Pick up the _OSC(x,y,tmp,fmt) macro. */
+#define _WANT_ISC 1
+#include "scaffold.c"
+
+/* Inspired by GLIBC stdio-common/tfformat.c */
+typedef struct{
+ int line;
+ decimal32 expect;
+ const char *d;
+ const char *fmt;
+ decimal32 tmp;
+} d32_type;
+
+d32_type istream_d32s[] =
+{
+ {__LINE__, 0.0000006E-90DF, "6e-97", "%Ha", -1.0DF},
+ {__LINE__, 0.0000006E-90DF, "6E-97", "%Ha", -1.0DF },
+ /* Test where specified precision '10' exceeds __DEC32_MANT_DIG__.
+ * This should reset precision to __DEC32_MANT_DIG__. */
+ {__LINE__, 0.6666666666E-90DF, "6.666667E-91", "%Ha", -1.0DF },
+ {0,0,0,0,0}
+};
+
+typedef struct{
+ int line;
+ decimal64 expect;
+ const char *d;
+ const char *fmt;
+ decimal64 tmp;
+} d64_type;
+
+d64_type istream_d64s[] =
+{
+ {__LINE__, -9.999E-3DD, "-0.009999", "%Da", -1.0DD},
+ {__LINE__, -9.999E-3DD, "-9.999000e-03", "%Da", -1.0DD},
+ {__LINE__, -9.999E-3DD, "-9.999E-03", "%Da", -1.0DD},
+ {__LINE__, -9.999E-3DD, "-0.009999", "%Da", -1.0DD},
+ {__LINE__, __builtin_infd64(), "inf", "%Da", -1.0DD},
+ {__LINE__, __builtin_infd64(), "INF", "%Da", -1.0DD},
+ {__LINE__, (0.0DD * __builtin_infd64()), "NAN", "%Da", -1.0DD},
+ {__LINE__, (0.0DD * __builtin_infd64()), "nan", "%Da", -1.0DD},
+ {0,0,0,0,0}
+};
+
+typedef struct{
+ int line;
+ decimal128 expect;
+ const char *d;
+ const char *fmt;
+ decimal128 tmp;
+} d128_type;
+
+d128_type istream_d128s[] =
+{
+ {__LINE__, -1234.57DL, "-1234.57", "%DDa", -1.0DL},
+ {__LINE__, -1234.57DL, "-1234.57", "%DDa", 0.0DL},
+ {__LINE__, -1234.57DL, "-1234.57000", "%DDa", -1.0DL},
+ {__LINE__, -1234.5679DL, "-1234.5679", "%DDa", -1.0DL},
+ {__LINE__, -12345678912345678.9123455678DL, "-12345678912345678.9123455678","%DDa", -1.0DL},
+ {0,0,0,0,0}
+};
+
+int main(void)
+{
+ d32_type *d32ptr;
+ d64_type *d64ptr;
+ d128_type *d128ptr;
+ int fail_save = 0;
+ for (d32ptr = istream_d32s; d32ptr->line; d32ptr++)
+ {
+ _ISC_P(__FILE__,d32ptr->line, d32ptr->expect,d32ptr->d,d32ptr->tmp,d32ptr->fmt);
+ }
+
+ for (d64ptr = istream_d64s; d64ptr->line; d64ptr++)
+ {
+ _ISC_P(__FILE__,d64ptr->line, d64ptr->expect,d64ptr->d,d64ptr->tmp,d64ptr->fmt);
+ }
+
+ for (d128ptr = istream_d128s; d128ptr->line; d128ptr++)
+ {
+ _ISC_P(__FILE__,d128ptr->line, d128ptr->expect,d128ptr->d,d128ptr->tmp, d128ptr->fmt);
+ }
+
+ _REPORT();
+
+ /* fail comes from scaffold.c */
+ return fail;
+
+}
Modified: libdfp/trunk/tests/test-strtod.c
==============================================================================
--- libdfp/trunk/tests/test-strtod.c (original)
+++ libdfp/trunk/tests/test-strtod.c Tue Jan 10 18:31:52 2012
@@ -1,6 +1,6 @@
/* Test strtod[32|64|128] facility.
- Copyright (C) 2010 Free Software Foundation, Inc.
+ Copyright (C) 2010, 2012 Free Software Foundation, Inc.
This file is part of the Decimal Floating Point C Library.
@@ -70,6 +70,7 @@
{__LINE__, "3.14", 3.140000DF, 3.140000DD, 3.140000DL },
{__LINE__, "3.14e-2", 0.031400DF, 0.031400DD, 0.031400DL },
{__LINE__, "1234.5678910111213e-5", 0.01234568DF ,0.01234567891011121DD ,0.012345678910111213DL },
+ {__LINE__, "-1234.57", -1234.57F, -1234.57DD, -1234.57DL},
{0,0,0,0,0 }
};
_______________________________________________
Commits mailing list
Commits@xxxxxxxxxx
http://eglibc.org/cgi-bin/mailman/listinfo/commits