#include <iostream>
#include <iomanip>
#include <cfenv>
#include "printer.hpp"
using std::cout;
using std::cerr;
using std::clog;
using std::endl;
using std::cin;
template<fxd::fixed_point F>
void
test(F x)
{
std::fesetround(FE_TOWARDZERO);
cout << "testing " << x << ":\n";
F a = std::sqrt(to_float(x));
cout << " std::sqrt = ";
print(a);
cout << '\n';
cout << " fxd::sqrt = ";
print(b);
if (b - a)
cout << " diff = " << (b - a);
cout << '\n';
cout << " fxd::sqrt_bin = ";
print(c);
if (c - a)
cout << " diff = " << (c - a);
cout << '\n';
cout << endl;
}
int main()
{
for (auto s : {
0.0, 1.0, 0.5, 0.25, 0.0625,
1.5, 2.0, 3.0,
9.0, 16.0, 25.0, 100.0, 121.0
}) {
test<Fxd>(s);
}
Fxd val;
while ((cout << "Input a number (between 0 and "
<< std::setprecision(std::numeric_limits<Fxd>::max_digits10)
<< std::numeric_limits<Fxd>::max() << "): ") && (cin >> val))
test(val);
cout << endl;
}
Includes all of libfxd headers.
constexpr Fxd sqrt(Fxd x) noexcept
Same as std::sqrt().
Fxd sqrt_bin(Fxd x) noexcept
The fixed-point class template.