summaryrefslogtreecommitdiff
path: root/libstdc++-v3/src/c++11/compatibility-ldbl-alt128.cc
blob: 7fb66917db136d47b4a555a4396af10217859ae8 (plain)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// Compatibility symbols for alternate 128-bit long-double format -*- C++ -*-

// Copyright (C) 2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This 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 General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

#define _GLIBCXX_USE_CXX11_ABI 0
#include <locale>

#ifdef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT

#if ! defined __LONG_DOUBLE_IBM128__ && ! defined __LONG_DOUBLE_IEEE128__
#error "compatibility-ldbl-alt128.cc must only be compiled for 128-bit long double"
#endif

#define C char
#define C_is_char
#include "locale-inst-numeric.h"
#include "locale-inst-monetary.h"
#include "compatibility-ldbl-facets-aliases.h"

#ifdef _GLIBCXX_USE_WCHAR_T
# undef C
# undef C_is_char
# define C wchar_t
# include "locale-inst-numeric.h"
# include "locale-inst-monetary.h"
# include "compatibility-ldbl-facets-aliases.h"
# undef C
#endif

#include <limits>
#include <functional>

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

  // long double
  const bool numeric_limits<long double>::is_specialized;
  const int  numeric_limits<long double>::digits;
  const int  numeric_limits<long double>::digits10;
  const int  numeric_limits<long double>::max_digits10;
  const bool numeric_limits<long double>::is_signed;
  const bool numeric_limits<long double>::is_integer;
  const bool numeric_limits<long double>::is_exact;
  const int  numeric_limits<long double>::radix;
  const int  numeric_limits<long double>::min_exponent;
  const int  numeric_limits<long double>::min_exponent10;
  const int  numeric_limits<long double>::max_exponent;
  const int  numeric_limits<long double>::max_exponent10;
  const bool numeric_limits<long double>::has_infinity;
  const bool numeric_limits<long double>::has_quiet_NaN;
  const bool numeric_limits<long double>::has_signaling_NaN;
  const float_denorm_style numeric_limits<long double>::has_denorm;
  const bool numeric_limits<long double>::has_denorm_loss;
  const bool numeric_limits<long double>::is_iec559;
  const bool numeric_limits<long double>::is_bounded;
  const bool numeric_limits<long double>::is_modulo;
  const bool numeric_limits<long double>::traps;
  const bool numeric_limits<long double>::tinyness_before;
  const float_round_style numeric_limits<long double>::round_style;

  template<>
    void
    __convert_to_v(const char* __s, long double& __v, ios_base::iostate& __err,
		   const __c_locale& __cloc) throw()
    {
      char* __sanity;
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
      // Prefer strtold_l, as __strtold_l isn't prototyped in more recent
      // glibc versions.
      __v = strtold_l(__s, &__sanity, __cloc);
#else
      __v = __strtold_l(__s, &__sanity, __cloc);
#endif

      // _GLIBCXX_RESOLVE_LIB_DEFECTS
      // 23. Num_get overflow result.
      if (__sanity == __s || *__sanity != '\0')
	{
	  __v = 0.0l;
	  __err = ios_base::failbit;
	}
      else if (__v == numeric_limits<long double>::infinity())
	{
	  __v = numeric_limits<long double>::max();
	  __err = ios_base::failbit;
	}
      else if (__v == -numeric_limits<long double>::infinity())
	{
	  __v = -numeric_limits<long double>::max();
	  __err = ios_base::failbit;
	}
    }

  namespace
  {
    alignas(money_get<char>) char money_get_c[sizeof(money_get<char>)];
    alignas(money_put<char>) char money_put_c[sizeof(money_put<char>)];
    alignas(num_get<char>) char num_get_c[sizeof(num_get<char>)];
    alignas(num_put<char>) char num_put_c[sizeof(num_put<char>)];
#ifdef _GLIBCXX_USE_WCHAR_T
    alignas(money_get<wchar_t>) char money_get_w[sizeof(money_get<wchar_t>)];
    alignas(money_put<wchar_t>) char money_put_w[sizeof(money_put<wchar_t>)];
    alignas(num_get<wchar_t>) char num_get_w[sizeof(num_get<wchar_t>)];
    alignas(num_put<wchar_t>) char num_put_w[sizeof(num_put<wchar_t>)];
#endif
  }

  extern void
  __locale_Impl_init_extra_ldbl128(
      function<void(const locale::id*, const locale::facet*)>,
      bool);

  void
  locale::_Impl::_M_init_extra_ldbl128(bool classic)
  {
    if (classic)
      {
	_M_init_facet(new (&money_get_c) money_get<char>(1));
	_M_init_facet(new (&money_put_c) money_put<char>(1));
	_M_init_facet(new (&num_get_c) num_get<char>(1));
	_M_init_facet(new (&num_put_c) num_put<char>(1));
#ifdef _GLIBCXX_USE_WCHAR_T
	_M_init_facet(new (&money_get_w) money_get<wchar_t>(1));
	_M_init_facet(new (&money_put_w) money_put<wchar_t>(1));
	_M_init_facet(new (&num_get_w) num_get<wchar_t>(1));
	_M_init_facet(new (&num_put_w) num_put<wchar_t>(1));
#endif
      }
    else
      {
	_M_init_facet(new money_get<char>);
	_M_init_facet(new money_put<char>);
	_M_init_facet(new num_get<char>);
	_M_init_facet(new num_put<char>);
#ifdef _GLIBCXX_USE_WCHAR_T
	_M_init_facet(new money_get<wchar_t>);
	_M_init_facet(new money_put<wchar_t>);
	_M_init_facet(new num_get<wchar_t>);
	_M_init_facet(new num_put<wchar_t>);
#endif
      }

#if _GLIBCXX_USE_DUAL_ABI
    __locale_Impl_init_extra_ldbl128(
	[this](const locale::id* i, const facet* f) {
	    _M_install_facet(i, f);
	},
	classic);
#endif
  }

_GLIBCXX_END_NAMESPACE_VERSION
} // namespace

#include <istream>
#include <ostream>

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
  template istream& istream::operator>>(long double&);
  template istream& istream::_M_extract(long double&);
  template ostream& ostream::operator<<(long double);
  template ostream& ostream::_M_insert(long double);
#ifdef _GLIBCXX_USE_WCHAR_T
  template wistream& wistream::operator>>(long double&);
  template wistream& wistream::_M_extract(long double&);
  template wostream& wostream::operator<<(long double);
  template wostream& wostream::_M_insert(long double);
#endif
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace

#include <complex>

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
  template
    basic_istream<char, char_traits<char> >&
    operator>>(basic_istream<char, char_traits<char> >&,
	       complex<long double>&);
  template
    basic_ostream<char, char_traits<char> >&
    operator<<(basic_ostream<char, char_traits<char> >&,
               const complex<long double>&);
#ifdef _GLIBCXX_USE_WCHAR_T
  template
    basic_istream<wchar_t, char_traits<wchar_t> >&
    operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&,
               complex<long double>&);
  template
    basic_ostream<wchar_t, char_traits<wchar_t> >&
    operator<<(basic_ostream<wchar_t, char_traits<wchar_t> >&,
               const complex<long double>&);
#endif
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace

#include <cmath>
#include <tr1/functional>

// For std::tr1::hash<long double>::operator()
#include "../c++98/hash-long-double-tr1-aux.cc"

// std::tr1::hash<long double>::operator()
// and std::hash<long double>::operator()
// are the same, no need to duplicate them.
#ifdef __LONG_DOUBLE_IBM128__
extern "C" size_t
_ZNKSt4hashIgEclEg (void)
  __attribute__((pure))
  __attribute__((alias ("_ZNKSt3tr14hashIgEclEg")));
#elif __LONG_DOUBLE_IEEE128__
extern "C" size_t
_ZNKSt4hashIu9__ieee128EclEu9__ieee128 (void)
  __attribute__((pure))
  __attribute__((alias ("_ZNKSt3tr14hashIu9__ieee128EclEu9__ieee128")));
#else
# error "Configuration error"
#endif

#endif