16 #include <my_global.h>
20 #define MAX_NEGATIVE_NUMBER ((ulonglong) LL(0x8000000000000000))
22 #define LFACTOR ULL(1000000000)
23 #define LFACTOR1 ULL(10000000000)
24 #define LFACTOR2 ULL(100000000000)
26 static unsigned long lfactor[9]=
28 1L, 10L, 100L, 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L
74 longlong my_strtoll10(
const char *nptr,
char **endptr,
int *error)
76 const char *s, *end, *start, *n_end, *true_end;
79 unsigned long i, j, k;
82 ulong cutoff, cutoff2, cutoff3;
89 while (s != end && (*s ==
' ' || *s ==
'\t'))
97 while (*s ==
' ' || *s ==
'\t')
113 cutoff= MAX_NEGATIVE_NUMBER / LFACTOR2;
114 cutoff2= (MAX_NEGATIVE_NUMBER % LFACTOR2) / 100;
115 cutoff3= MAX_NEGATIVE_NUMBER % 100;
125 cutoff= ULONGLONG_MAX / LFACTOR2;
126 cutoff2= ULONGLONG_MAX % LFACTOR2 / 100;
127 cutoff3= ULONGLONG_MAX % 100;
145 if ((c= (*s-
'0')) > 9)
148 n_end= ++s+ INIT_CNT-1;
154 for (; s != n_end ; s++)
156 if ((c= (*s-
'0')) > 9)
166 n_end= true_end= s + INIT_CNT;
171 if ((c= (*s-
'0')) > 9)
174 }
while (++s != n_end);
181 if ((c= (*s-
'0')) > 9)
186 if (++s == end || (c= (*s-
'0')) > 9)
189 *endptr= (
char*) ++s;
192 if (s != end && (c= (*s-
'0')) <= 9)
196 if (i > cutoff || (i == cutoff && (j > cutoff2 || (j == cutoff2 &&
199 li=i*LFACTOR2+ (ulonglong) j*100 + k;
200 return (longlong) li;
203 *error= MY_ERRNO_ERANGE;
204 return negative ? LONGLONG_MIN : (longlong) ULONGLONG_MAX;
208 return (negative ? ((longlong) -(long) i) : (longlong) i);
211 li= (ulonglong) i * lfactor[(uint) (s-start)] + j;
213 return (negative ? -((longlong) li) : (longlong) li);
216 li=(ulonglong) i*LFACTOR+ (ulonglong) j;
218 return (negative ? -((longlong) li) : (longlong) li);
221 li=(ulonglong) i*LFACTOR1+ (ulonglong) j * 10 + k;
225 if (li > MAX_NEGATIVE_NUMBER)
227 return -((longlong) li);
229 return (longlong) li;
233 *error= MY_ERRNO_EDOM;
234 *endptr= (
char *) nptr;