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 140 141 142 143 144
|
/* Test ostream operator in cpp compat header <dfp/decimal/decimal>.
Copyright (C) 2011-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>
using namespace std;
using namespace std::decimal;
/* Pick up the _OSC(x,y,precision,upper,spec) macro. */
#define _WANT_OSC 1
#include "scaffold.c"
/* Inspired by GLIBC stdio-common/tfformat.c */
typedef struct{
int line;
decimal32 d;
const char *expect;
int precision; /* -1 means unspecified. */
char upper; /* l or u */
char spec; /* a, e, f */
} d32_type;
d32_type ostream_d32s[] =
{
{__LINE__, 0.0000006E-90DF, "6e-97", -1, 'l', 'a' },
{__LINE__, 0.0000006E-90DF, "6E-97", -1, 'u', 'a' },
/* Test where specified precision '10' exceeds __DEC32_MANT_DIG__.
* This should reset precision to __DEC32_MANT_DIG__. */
{__LINE__, 0.6666666666E-90DF, "6.666667E-91", 10, 'u', 'a' },
{0,0,0,0,0,0}
};
typedef struct{
int line;
decimal64 d;
const char *expect;
int precision; /* -1 means unspecified. */
char upper; /* l or u */
char spec; /* a, e, f */
} d64_type;
d64_type ostream_d64s[] =
{
{__LINE__, -9.999E-3DD, "-0.009999", -1, 'l', 'f' },
{__LINE__, -9.999E-3DD, "-9.999000e-03", -1, 'l', 'e' },
{__LINE__, -9.999E-3DD, "-9.999E-03", 3, 'u', 'e' },
{__LINE__, -9.999E-3DD, "-0.009999", -1, 'l', 'a' },
{__LINE__, __builtin_infd64(), "inf", -1, 'l', 'a' },
{__LINE__, __builtin_infd64(), "INF", -1, 'u', 'a' },
{__LINE__, (0.0DD * __builtin_infd64()), "NAN", -1, 'u', 'a' },
{__LINE__, (0.0DD * __builtin_infd64()), "nan", -1, 'l', 'a' },
{__LINE__, -(0.0DD * __builtin_infd64()), "-NAN", -1, 'u', 'a' },
{__LINE__, -(0.0DD * __builtin_infd64()), "-nan", -1, 'l', 'a' },
/* Due to the lack of direction in the C++ DFP TR there is no indication
that a/A conv specifiers should accept precision. */
{__LINE__, 4.000000000000000e+384DD, "4.000000000000000e+384", -1, 'l', 'a' },
{__LINE__, 4.000000000000000e+384DD, "4.000000000000000e+384", 7, 'l', 'a' },
{__LINE__, 4.000000000000000e+384DD, "4.000000000000000e+384", 6, 'l', 'a' },
{__LINE__, 4.000000000000000e+384DD, "4.000000000000000e+384", 19, 'l', 'a' },
{0,0,0,0,0,0}
};
typedef struct{
int line;
decimal128 d;
const char *expect;
int precision; /* -1 means unspecified. */
char upper; /* l or u */
char spec; /* a, e, f */
} d128_type;
d128_type ostream_d128s[] =
{
{__LINE__, -1234.56789123456789123455678DL, "-1234.56789123456789123455678", -1, 'l', 'a' },
{__LINE__, -1234.56789123456789123455678DL, "-1234.56789123456789123455678", 8, 'l', 'a' },
{__LINE__, -12345678912345678.9123455678DL, "-12345678912345678.9123455678", 10, 'u', 'f' },
{__LINE__, (0.0DL * __builtin_infd128()), "NAN", -1, 'u', 'a' },
{__LINE__, (0.0DL * __builtin_infd128()), "nan", -1, 'l', 'a' },
{__LINE__, -(0.0DL * __builtin_infd128()), "-NAN", -1, 'u', 'a' },
{__LINE__, -(0.0DL * __builtin_infd128()), "-nan", -1, 'l', 'a' },
{0,0,0,0,0,0}
};
int main(void)
{
d32_type *d32ptr;
d64_type *d64ptr;
d128_type *d128ptr;
for (d32ptr = ostream_d32s; d32ptr->line; d32ptr++)
{
_OSC_P(__FILE__,d32ptr->line, d32ptr->expect,d32ptr->d,d32ptr->precision,d32ptr->upper,d32ptr->spec);
}
for (d64ptr = ostream_d64s; d64ptr->line; d64ptr++)
{
_OSC_P(__FILE__,d64ptr->line, d64ptr->expect,d64ptr->d,d64ptr->precision,d64ptr->upper,d64ptr->spec);
}
for (d128ptr = ostream_d128s; d128ptr->line; d128ptr++)
{
_OSC_P(__FILE__,d128ptr->line, d128ptr->expect,d128ptr->d,d128ptr->precision,d128ptr->upper,d128ptr->spec);
}
_REPORT();
/* fail comes from scaffold.c */
return fail;
}
|