1 // Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
23 struct SincosReference
27 std::tuple
<const T
&, const T
&, const T
&>
29 { return std::tie(x
, s
, c
); }
36 std::tuple
<const T
&, const T
&>
38 { return std::tie(x
, ref
); }
48 : size_(0), data_(nullptr) {}
50 Array(size_t s
, const T
*p
)
51 : size_(s
), data_(p
) {}
59 { return data_
+ size_
; }
67 struct sincos
{ static constexpr const char *const str
= "sincos"; };
68 struct atan
{ static constexpr const char *const str
= "atan"; };
69 struct asin
{ static constexpr const char *const str
= "asin"; };
70 struct acos
{ static constexpr const char *const str
= "acos"; };
71 struct log
{ static constexpr const char *const str
= "ln"; };
72 struct log2
{ static constexpr const char *const str
= "log2"; };
73 struct log10
{ static constexpr const char *const str
= "log10"; };
77 struct testdatatype_for_function
80 using type
= Reference
<T
>;
84 struct testdatatype_for_function
<function::sincos
>
87 using type
= SincosReference
<T
>;
90 template <class F
, class T
>
91 using testdatatype_for_function_t
92 = typename testdatatype_for_function
<F
>::template type
<T
>;
99 StaticDeleter(const T
*p
)
106 template <class F
, class T
>
107 inline std::string
filename()
109 static_assert(std::is_floating_point
<T
>::value
, "");
110 static const auto cache
111 = std::string("reference-") + F::str
112 + (sizeof(T
) == 4 && std::__digits_v
<T
> == 24
113 && std::__max_exponent_v
<T
> == 128
116 && std::__digits_v
<T
> == 53
117 && std::__max_exponent_v
<T
> == 1024
119 : (sizeof(T
) == 16 && std::__digits_v
<T
> == 64
120 && std::__max_exponent_v
<T
> == 16384
122 : (sizeof(T
) == 16 && std::__digits_v
<T
> == 113
123 && std::__max_exponent_v
<T
> == 16384
130 template <class Fun
, class T
, class Ref
= testdatatype_for_function_t
<Fun
, T
>>
134 static Array
<Ref
> data
;
135 if (data
.data_
== nullptr)
137 FILE* file
= std::fopen(filename
<Fun
, T
>().c_str(), "rb");
140 std::fseek(file
, 0, SEEK_END
);
141 const size_t size
= std::ftell(file
) / sizeof(Ref
);
143 auto mem
= new Ref
[size
];
144 static StaticDeleter
<Ref
> _cleanup(data
.data_
);
145 data
.size_
= std::fread(mem
, sizeof(Ref
), size
, file
);
153 "%s:%d: the reference data %s does not exist in the current "
154 "working directory.\n",
155 __FILE__
, __LINE__
, filename
<Fun
, T
>().c_str());