#include <math.h>
#include <stdio.h>
#define INFINITY             (0x1P+127F)
#define NAN                  (0x1P8+127F) /* QUIET NAN */
long double _stdcall ___matherr(const char *name, _mexcep errl)
{
    long double rv = INFINITY;
    char *type = "Unknown";
    int val = 0;
    switch(errl) {
        case DOMAIN:
            type = "DOMAIN" ;
            break ;
        case OVERFLOW:
            type = "OVERFLOW" ;
            break;
        case UNDERFLOW:
            val = 1;
            rv = 0;
            type = "UNDERFLOW" ;
            break;
        case SING:
            type = "SINGULARITY" ;
            rv = INFINITY;
            break ;
        case TLOSS:
            val = 1;
            type = "LOSS OF PRECISION" ; /* inexact */
            break ;
        case STACKFAULT:
            type = "STACK FAULT" ; /* stack overflow */
            break;
    }
//    if (!_matherr(val))
        printf("%s: %s error\n",name,type);
    return rv;
}
