#include <stdlib.h>
#include <locale.h>
#include <errno.h>
 
extern int errno;

/*
 * The following example uses the wcstod subroutine to convert
 * a wide character string to a double-precision floating point
 */
int main(int argc, char **argv) {
    wchar_t  *pwcs, *endptr;
    double   retval;
 
    setlocale(LC_ALL, "");
    
    /*
     * Let pwcs point to a wide character null terminated
     * string containing a floating point value.
     */
    errno = 0; /*  set errno to  zero  */
    retval = wcstod(pwcs, &endptr);
 
    if(errno != 0) { /*  errno has changed, so error has occurred */
        if (errno == ERANGE){
          
            /* 
             * correct value is outside range of
             * representable values. Case of overflow
             * error
             */
            if ((retval == HUGE_VAL) || (retval == -HUGE_VAL)){
                /* Error case. Handle accordingly.  */
            } else if (retval == 0){
                /* correct value causes underflow   */
                /* Handle appropriately             */
            }
        }
    }
    /*  retval contains the double.  */
    printf("Double from wide-character: %d\n", retval);
    return (0);
}