1 /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ 2 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ 3 #include <stdlib.h> 4 5 6 /* 7 * @implemented 8 */ 9 #if 0 //FIXME: Compare with wcstod in wcs.c 10 double wcstod(const wchar_t *s, wchar_t **sret) 11 { 12 long double r; /* result */ 13 int e; /* exponent */ 14 long double d; /* scale */ 15 int sign; /* +- 1.0 */ 16 int esign; 17 int i; 18 int flags=0; 19 20 r = 0.0; 21 sign = 1; 22 e = 0; 23 esign = 1; 24 25 while ((*s == L' ') || (*s == L'\t')) 26 s++; 27 28 if (*s == L'+') 29 s++; 30 else if (*s == L'-') 31 { 32 sign = -1; 33 s++; 34 } 35 36 while ((*s >= L'0') && (*s <= L'9')) 37 { 38 flags |= 1; 39 r *= 10.0; 40 r += *s - L'0'; 41 s++; 42 } 43 44 if (*s == L'.') 45 { 46 d = 0.1L; 47 s++; 48 while ((*s >= L'0') && (*s <= L'9')) 49 { 50 flags |= 2; 51 r += d * (*s - L'0'); 52 s++; 53 d *= 0.1L; 54 } 55 } 56 57 if (flags == 0) 58 { 59 if (sret) 60 *sret = (wchar_t *)s; 61 return 0; 62 } 63 64 if ((*s == L'e') || (*s == L'E')) 65 { 66 s++; 67 if (*s == L'+') 68 s++; 69 else if (*s == L'-') 70 { 71 s++; 72 esign = -1; 73 } 74 if ((*s < L'0') || (*s > L'9')) 75 { 76 if (sret) 77 *sret = (wchar_t *)s; 78 return r; 79 } 80 81 while ((*s >= L'0') && (*s <= L'9')) 82 { 83 e *= 10; 84 e += *s - L'0'; 85 s++; 86 } 87 } 88 89 if (esign < 0) 90 for (i = 1; i <= e; i++) 91 r *= 0.1L; 92 else 93 for (i = 1; i <= e; i++) 94 r *= 10.0; 95 96 if (sret) 97 *sret = (wchar_t *)s; 98 return r * sign; 99 } 100 #endif 101