/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/* File name hypothetical.chf */

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

double hypothetical(double x, double y) {
    void *fptr, *handle;
    double retval;

    if(isnan(y)) /* some native implementation give hypothetical(+/-Inf, NaN) == Inf */
      return NaN;
    handle = dlopen("libhypothetical.dl", RTLD_LAZY);
    if(handle == NULL) {
      fprintf(stderr, "Error: dlopen(): %s\n", dlerror());
      fprintf(stderr, "       cannot get handle in hypothetical.chf\n");
      return NaN;
    } 
    fptr = dlsym(handle, "hypothetical_chdl");
    if(fptr == NULL)  {
       fprintf(stderr, "Error: %s(): dlsym(): %s\n", __func__, dlerror());
       return NaN;
    }
    dlrunfun(fptr, &retval, hypothetical, x, y);
    if(dlclose(handle)!=0) {
       fprintf(stderr, "Error: %s(): dlclose(): %s\n", __func__, dlerror());
       return NaN;
    }
    return retval;
}
