#include <mpfr.h>
#include "fenv_mpfr.h"
#include <stdint.h>
typedef union {long double f; struct {uint64_t m; uint16_t e;};} b80u80_t;
inline static int
is_nan (long double x)
{
b80u80_t v = {.f = x};
return ((v.e&0x7fff) == 0x7fff && (v.m != (1ull << 63)));
}
inline static int
is_snan (long double x)
{
b80u80_t v = {.f = x};
return is_nan (x) && (!((v.m>>62)&1));
}
long double
ref_hypotl (long double x, long double y)
{
if (is_snan (x) || is_snan (y)) {
mpfr_set_nanflag (); return x + y;
}
mpfr_t z, _x, _y;
mpfr_exp_t emin = mpfr_get_emin ();
mpfr_set_emin (-16444);
mpfr_inits2 (64, z, _x, _y, NULL);
mpfr_set_ld (_x, x, MPFR_RNDN);
mpfr_set_ld (_y, y, MPFR_RNDN);
int inex = mpfr_hypot (z, _x, _y, rnd2[rnd]);
mpfr_subnormalize (z, inex, rnd2[rnd]);
long double ret = mpfr_get_ld (z, rnd2[rnd]);
mpfr_clears (z, _x, _y, NULL);
mpfr_set_emin (emin);
return ret;
}