/*
 * Kahan challenge:
 *
 * "Getting the same answer with increased precision
 *  means the answer is correct." (?)
 */

#include <stdio.h>
#include <math.h>

typedef long double real;

real e(real x);
real q(real x);
real h(real x);

real e (real x)
{
    if (x == 0.L)
    {
        return 1.L;
    }
    else
    {
        return (expl(x) - 1.L)/x;
    }
}

real q (real x)
{
    return fabsl (-x + sqrtl (x*x + 1.L)) - 1.L/(x + sqrtl (x*x + 1.L));
}

real h (real x)
{
    return e( powl(q(x), 2.L));
}

int main (void)
{
    real i;

    for (i = 15.L; i < 18.L; i += 1.L)
    {
        printf("%20.4Lf     %20.14Lf\n", i, h(i));
    }
    i = 9999.L;
    printf("%20.4Lf     %20.14Lf\n", i, h(i));  // correct results - all 1s

    return 0;
}