Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenstrtold.c
Go to the documentation of this file.
00001 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ 00002 #include <stdlib.h> 00003 #include <msvcrt/ctype.h> 00004 00005 static double powten[] = 00006 { 00007 1e1L, 1e2L, 1e4L, 1e8L, 1e16L, 1e32L, 1e64L, 1e128L, 1e256L, 00008 #ifdef __GNUC__ 00009 1e512L, 1e512L*1e512L, 1e2048L, 1e4096L 00010 #else 00011 1e256L, 1e256L, 1e256L, 1e256L 00012 #endif 00013 }; 00014 00015 long double 00016 _strtold(const char *s, char **sret) 00017 { 00018 double r; /* result */ 00019 int e, ne; /* exponent */ 00020 int sign; /* +- 1.0 */ 00021 int esign; 00022 int flags=0; 00023 int l2powm1; 00024 00025 r = 0.0L; 00026 sign = 1; 00027 e = ne = 0; 00028 esign = 1; 00029 00030 while(*s && isspace(*s)) 00031 s++; 00032 00033 if (*s == '+') 00034 s++; 00035 else if (*s == '-') 00036 { 00037 sign = -1; 00038 s++; 00039 } 00040 00041 while ((*s >= '0') && (*s <= '9')) 00042 { 00043 flags |= 1; 00044 r *= 10.0L; 00045 r += *s - '0'; 00046 s++; 00047 } 00048 00049 if (*s == '.') 00050 { 00051 s++; 00052 while ((*s >= '0') && (*s <= '9')) 00053 { 00054 flags |= 2; 00055 r *= 10.0L; 00056 r += *s - '0'; 00057 s++; 00058 ne++; 00059 } 00060 } 00061 if (flags == 0) 00062 { 00063 if (sret) 00064 *sret = (char *)s; 00065 return 0.0L; 00066 } 00067 00068 if ((*s == 'e') || (*s == 'E')) 00069 { 00070 s++; 00071 if (*s == '+') 00072 s++; 00073 else if (*s == '-') 00074 { 00075 s++; 00076 esign = -1; 00077 } 00078 while ((*s >= '0') && (*s <= '9')) 00079 { 00080 e *= 10; 00081 e += *s - '0'; 00082 s++; 00083 } 00084 } 00085 if (esign < 0) 00086 { 00087 esign = -esign; 00088 e = -e; 00089 } 00090 e = e - ne; 00091 if (e < -4096) 00092 { 00093 /* possibly subnormal number, 10^e would overflow */ 00094 r *= 1.0e-2048L; 00095 e += 2048; 00096 } 00097 if (e < 0) 00098 { 00099 e = -e; 00100 esign = -esign; 00101 } 00102 if (e >= 8192) 00103 e = 8191; 00104 if (e) 00105 { 00106 double d = 1.0L; 00107 l2powm1 = 0; 00108 while (e) 00109 { 00110 if (e & 1) 00111 d *= powten[l2powm1]; 00112 e >>= 1; 00113 l2powm1++; 00114 } 00115 if (esign > 0) 00116 r *= d; 00117 else 00118 r /= d; 00119 } 00120 if (sret) 00121 *sret = (char *)s; 00122 return r * sign; 00123 00124 return 0; 00125 } Generated on Fri May 25 2012 04:35:10 for ReactOS by
1.7.6.1
|