File: test-istream.cpp

package info (click to toggle)
libdfp 1.0.17-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,172 kB
  • sloc: ansic: 255,724; sh: 4,225; makefile: 703; awk: 461; python: 432; cpp: 254
file content (139 lines) | stat: -rw-r--r-- 3,860 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* Test istream operator in cpp compat header <dfp/decimal/decimal>.

   Copyright (C) 2012-2015 Free Software Foundation, Inc.

   This file is part of the Decimal Floating Point C Library.

   Author(s): Ryan S. Arnold <rsa@us.ibm.com>

   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., 51 Franklin
   Street, Fifth Floor, Boston, MA 02110-1301 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>

#include <math.h>

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__, 4E384DD, "4.0E384", "%Da", -1.0DD},
  /* You can't value compare nan to nan.  */
  /* {__LINE__, (0.0DD * __builtin_infd64()), "NAN", "%Da", -1.0DD},  */
  /* You can't value compare nan to nan.  */
  /* {__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;

  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;

}