30 "00" "01" "02" "03" "04" "05" "06" "07" "08" "09"
31 "10" "11" "12" "13" "14" "15" "16" "17" "18" "19"
32 "20" "21" "22" "23" "24" "25" "26" "27" "28" "29"
33 "30" "31" "32" "33" "34" "35" "36" "37" "38" "39"
34 "40" "41" "42" "43" "44" "45" "46" "47" "48" "49"
35 "50" "51" "52" "53" "54" "55" "56" "57" "58" "59"
36 "60" "61" "62" "63" "64" "65" "66" "67" "68" "69"
37 "70" "71" "72" "73" "74" "75" "76" "77" "78" "79"
38 "80" "81" "82" "83" "84" "85" "86" "87" "88" "89"
39 "90" "91" "92" "93" "94" "95" "96" "97" "98" "99";
48 static const uint32 PowersOfTen[] = {
51 1000000, 10000000, 100000000,
60 return t + (v >= PowersOfTen[t]);
67 static const uint64 PowersOfTen[] = {
68 UINT64CONST(1), UINT64CONST(10),
69 UINT64CONST(100), UINT64CONST(1000),
70 UINT64CONST(10000), UINT64CONST(100000),
71 UINT64CONST(1000000), UINT64CONST(10000000),
72 UINT64CONST(100000000), UINT64CONST(1000000000),
73 UINT64CONST(10000000000), UINT64CONST(100000000000),
74 UINT64CONST(1000000000000), UINT64CONST(10000000000000),
75 UINT64CONST(100000000000000), UINT64CONST(1000000000000000),
76 UINT64CONST(10000000000000000), UINT64CONST(100000000000000000),
77 UINT64CONST(1000000000000000000), UINT64CONST(10000000000000000000)
85 return t + (v >= PowersOfTen[t]);
89 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
90 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
91 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
92 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
93 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
94 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
95 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
96 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
122 const char *firstdigit;
127 while (
likely(*ptr) && isspace((
unsigned char) *ptr))
136 else if (*ptr ==
'+')
140 if (ptr[0] ==
'0' && (ptr[1] ==
'x' || ptr[1] ==
'X'))
142 firstdigit = ptr += 2;
146 if (isxdigit((
unsigned char) *ptr))
151 tmp = tmp * 16 +
hexlookup[(
unsigned char) *ptr++];
153 else if (*ptr ==
'_')
157 if (*ptr ==
'\0' || !isxdigit((
unsigned char) *ptr))
164 else if (ptr[0] ==
'0' && (ptr[1] ==
'o' || ptr[1] ==
'O'))
166 firstdigit = ptr += 2;
170 if (*ptr >=
'0' && *ptr <=
'7')
175 tmp = tmp * 8 + (*ptr++ -
'0');
177 else if (*ptr ==
'_')
181 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'7')
188 else if (ptr[0] ==
'0' && (ptr[1] ==
'b' || ptr[1] ==
'B'))
190 firstdigit = ptr += 2;
194 if (*ptr >=
'0' && *ptr <=
'1')
199 tmp = tmp * 2 + (*ptr++ -
'0');
201 else if (*ptr ==
'_')
205 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'1')
218 if (isdigit((
unsigned char) *ptr))
223 tmp = tmp * 10 + (*ptr++ -
'0');
225 else if (*ptr ==
'_')
232 if (*ptr ==
'\0' || !isdigit((
unsigned char) *ptr))
245 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
256 return -((
int16) tmp);
266 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
267 errmsg(
"value \"%s\" is out of range for type %s",
272 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
273 errmsg(
"invalid input syntax for type %s: \"%s\"",
300 const char *firstdigit;
305 while (
likely(*ptr) && isspace((
unsigned char) *ptr))
314 else if (*ptr ==
'+')
318 if (ptr[0] ==
'0' && (ptr[1] ==
'x' || ptr[1] ==
'X'))
320 firstdigit = ptr += 2;
324 if (isxdigit((
unsigned char) *ptr))
329 tmp = tmp * 16 +
hexlookup[(
unsigned char) *ptr++];
331 else if (*ptr ==
'_')
335 if (*ptr ==
'\0' || !isxdigit((
unsigned char) *ptr))
342 else if (ptr[0] ==
'0' && (ptr[1] ==
'o' || ptr[1] ==
'O'))
344 firstdigit = ptr += 2;
348 if (*ptr >=
'0' && *ptr <=
'7')
353 tmp = tmp * 8 + (*ptr++ -
'0');
355 else if (*ptr ==
'_')
359 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'7')
366 else if (ptr[0] ==
'0' && (ptr[1] ==
'b' || ptr[1] ==
'B'))
368 firstdigit = ptr += 2;
372 if (*ptr >=
'0' && *ptr <=
'1')
377 tmp = tmp * 2 + (*ptr++ -
'0');
379 else if (*ptr ==
'_')
383 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'1')
396 if (isdigit((
unsigned char) *ptr))
401 tmp = tmp * 10 + (*ptr++ -
'0');
403 else if (*ptr ==
'_')
410 if (*ptr ==
'\0' || !isdigit((
unsigned char) *ptr))
423 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
434 return -((
int32) tmp);
444 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
445 errmsg(
"value \"%s\" is out of range for type %s",
450 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
451 errmsg(
"invalid input syntax for type %s: \"%s\"",
478 const char *firstdigit;
483 while (*ptr && isspace((
unsigned char) *ptr))
492 else if (*ptr ==
'+')
496 if (ptr[0] ==
'0' && (ptr[1] ==
'x' || ptr[1] ==
'X'))
498 firstdigit = ptr += 2;
502 if (isxdigit((
unsigned char) *ptr))
507 tmp = tmp * 16 +
hexlookup[(
unsigned char) *ptr++];
509 else if (*ptr ==
'_')
513 if (*ptr ==
'\0' || !isxdigit((
unsigned char) *ptr))
520 else if (ptr[0] ==
'0' && (ptr[1] ==
'o' || ptr[1] ==
'O'))
522 firstdigit = ptr += 2;
526 if (*ptr >=
'0' && *ptr <=
'7')
531 tmp = tmp * 8 + (*ptr++ -
'0');
533 else if (*ptr ==
'_')
537 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'7')
544 else if (ptr[0] ==
'0' && (ptr[1] ==
'b' || ptr[1] ==
'B'))
546 firstdigit = ptr += 2;
550 if (*ptr >=
'0' && *ptr <=
'1')
555 tmp = tmp * 2 + (*ptr++ -
'0');
557 else if (*ptr ==
'_')
561 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'1')
574 if (isdigit((
unsigned char) *ptr))
579 tmp = tmp * 10 + (*ptr++ -
'0');
581 else if (*ptr ==
'_')
588 if (*ptr ==
'\0' || !isdigit((
unsigned char) *ptr))
601 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
612 return -((int64) tmp);
622 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
623 errmsg(
"value \"%s\" is out of range for type %s",
628 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
629 errmsg(
"invalid input syntax for type %s: \"%s\"",
657 cvt = strtoul(s, &endptr, 0);
665 if ((errno && errno != ERANGE) || endptr == s)
667 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
668 errmsg(
"invalid input syntax for type %s: \"%s\"",
673 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
674 errmsg(
"value \"%s\" is out of range for type %s",
685 while (*endptr && isspace((
unsigned char) *endptr))
689 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
690 errmsg(
"invalid input syntax for type %s: \"%s\"",
708 #if PG_UINT32_MAX != ULONG_MAX
709 if (cvt != (
unsigned long) result &&
710 cvt != (
unsigned long) ((
int) result))
712 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
713 errmsg(
"value \"%s\" is out of range for type %s",
751 if ((errno && errno != ERANGE) || endptr == s)
753 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
754 errmsg(
"invalid input syntax for type %s: \"%s\"",
759 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
760 errmsg(
"value \"%s\" is out of range for type %s",
771 while (*endptr && isspace((
unsigned char) *endptr))
775 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
776 errmsg(
"invalid input syntax for type %s: \"%s\"",
821 while (
value >= 10000)
824 const uint32 c0 = (
c % 100) << 1;
825 const uint32 c1 = (
c / 100) << 1;
827 char *pos =
a + olength -
i;
839 char *pos =
a + olength -
i;
850 char *pos =
a + olength -
i;
856 *
a = (char) (
'0' +
value);
878 uvalue = (
uint32) 0 - uvalue;
907 while (
value >= 100000000)
909 const uint64 q =
value / 100000000;
912 const uint32 c = value3 % 10000;
913 const uint32 d = value3 / 10000;
914 const uint32 c0 = (
c % 100) << 1;
915 const uint32 c1 = (
c / 100) << 1;
916 const uint32 d0 = (d % 100) << 1;
917 const uint32 d1 = (d / 100) << 1;
919 char *pos =
a + olength -
i;
935 const uint32 c = value2 - 10000 * (value2 / 10000);
936 const uint32 c0 = (
c % 100) << 1;
937 const uint32 c1 = (
c / 100) << 1;
939 char *pos =
a + olength -
i;
949 const uint32 c = (value2 % 100) << 1;
950 char *pos =
a + olength -
i;
960 char *pos =
a + olength -
i;
965 *
a = (char) (
'0' + value2);
980 uint64 uvalue =
value;
985 uvalue = (uint64) 0 - uvalue;
1024 if (
value < 100 && minwidth == 2)
1031 if (
len >= minwidth)
1035 memset(
str,
'0', minwidth -
len);
1036 return str + minwidth;
#define strtou64(str, endptr, base)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
Assert(fmt[strlen(fmt) - 1] !='\n')
int64 pg_strtoint64_safe(const char *s, Node *escontext)
uint64 uint64in_subr(const char *s, char **endloc, const char *typname, Node *escontext)
int64 pg_strtoint64(const char *s)
int pg_ltoa(int32 value, char *a)
int32 pg_strtoint32_safe(const char *s, Node *escontext)
int pg_ulltoa_n(uint64 value, char *a)
int16 pg_strtoint16(const char *s)
static const char DIGIT_TABLE[200]
static int decimalLength32(const uint32 v)
uint32 uint32in_subr(const char *s, char **endloc, const char *typname, Node *escontext)
int pg_lltoa(int64 value, char *a)
static int decimalLength64(const uint64 v)
int pg_itoa(int16 i, char *a)
int32 pg_strtoint32(const char *s)
char * pg_ultostr(char *str, uint32 value)
char * pg_ultostr_zeropad(char *str, uint32 value, int32 minwidth)
int16 pg_strtoint16_safe(const char *s, Node *escontext)
static const int8 hexlookup[128]
int pg_ultoa_n(uint32 value, char *a)
static int pg_leftmost_one_pos32(uint32 word)
static int pg_leftmost_one_pos64(uint64 word)