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,
131 const char *firstdigit;
155 digit = (*ptr -
'0');
175 digit = (*ptr -
'0');
185 tmp = tmp * 10 + digit;
197 return -((
int16) tmp);
211 while (isspace((
unsigned char) *ptr))
220 else if (*ptr ==
'+')
224 if (ptr[0] ==
'0' && (ptr[1] ==
'x' || ptr[1] ==
'X'))
226 firstdigit = ptr += 2;
230 if (isxdigit((
unsigned char) *ptr))
235 tmp = tmp * 16 +
hexlookup[(
unsigned char) *ptr++];
237 else if (*ptr ==
'_')
241 if (*ptr ==
'\0' || !isxdigit((
unsigned char) *ptr))
248 else if (ptr[0] ==
'0' && (ptr[1] ==
'o' || ptr[1] ==
'O'))
250 firstdigit = ptr += 2;
254 if (*ptr >=
'0' && *ptr <=
'7')
259 tmp = tmp * 8 + (*ptr++ -
'0');
261 else if (*ptr ==
'_')
265 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'7')
272 else if (ptr[0] ==
'0' && (ptr[1] ==
'b' || ptr[1] ==
'B'))
274 firstdigit = ptr += 2;
278 if (*ptr >=
'0' && *ptr <=
'1')
283 tmp = tmp * 2 + (*ptr++ -
'0');
285 else if (*ptr ==
'_')
289 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'1')
302 if (*ptr >=
'0' && *ptr <=
'9')
307 tmp = tmp * 10 + (*ptr++ -
'0');
309 else if (*ptr ==
'_')
316 if (*ptr ==
'\0' || !isdigit((
unsigned char) *ptr))
329 while (isspace((
unsigned char) *ptr))
340 return -((
int16) tmp);
350 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
351 errmsg(
"value \"%s\" is out of range for type %s",
356 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
357 errmsg(
"invalid input syntax for type %s: \"%s\"",
393 const char *firstdigit;
417 digit = (*ptr -
'0');
437 digit = (*ptr -
'0');
447 tmp = tmp * 10 + digit;
459 return -((
int32) tmp);
473 while (isspace((
unsigned char) *ptr))
482 else if (*ptr ==
'+')
486 if (ptr[0] ==
'0' && (ptr[1] ==
'x' || ptr[1] ==
'X'))
488 firstdigit = ptr += 2;
492 if (isxdigit((
unsigned char) *ptr))
497 tmp = tmp * 16 +
hexlookup[(
unsigned char) *ptr++];
499 else if (*ptr ==
'_')
503 if (*ptr ==
'\0' || !isxdigit((
unsigned char) *ptr))
510 else if (ptr[0] ==
'0' && (ptr[1] ==
'o' || ptr[1] ==
'O'))
512 firstdigit = ptr += 2;
516 if (*ptr >=
'0' && *ptr <=
'7')
521 tmp = tmp * 8 + (*ptr++ -
'0');
523 else if (*ptr ==
'_')
527 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'7')
534 else if (ptr[0] ==
'0' && (ptr[1] ==
'b' || ptr[1] ==
'B'))
536 firstdigit = ptr += 2;
540 if (*ptr >=
'0' && *ptr <=
'1')
545 tmp = tmp * 2 + (*ptr++ -
'0');
547 else if (*ptr ==
'_')
551 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'1')
564 if (*ptr >=
'0' && *ptr <=
'9')
569 tmp = tmp * 10 + (*ptr++ -
'0');
571 else if (*ptr ==
'_')
578 if (*ptr ==
'\0' || !isdigit((
unsigned char) *ptr))
591 while (isspace((
unsigned char) *ptr))
602 return -((
int32) tmp);
612 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
613 errmsg(
"value \"%s\" is out of range for type %s",
618 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
619 errmsg(
"invalid input syntax for type %s: \"%s\"",
655 const char *firstdigit;
679 digit = (*ptr -
'0');
699 digit = (*ptr -
'0');
709 tmp = tmp * 10 + digit;
721 return -((int64) tmp);
735 while (isspace((
unsigned char) *ptr))
744 else if (*ptr ==
'+')
748 if (ptr[0] ==
'0' && (ptr[1] ==
'x' || ptr[1] ==
'X'))
750 firstdigit = ptr += 2;
754 if (isxdigit((
unsigned char) *ptr))
759 tmp = tmp * 16 +
hexlookup[(
unsigned char) *ptr++];
761 else if (*ptr ==
'_')
765 if (*ptr ==
'\0' || !isxdigit((
unsigned char) *ptr))
772 else if (ptr[0] ==
'0' && (ptr[1] ==
'o' || ptr[1] ==
'O'))
774 firstdigit = ptr += 2;
778 if (*ptr >=
'0' && *ptr <=
'7')
783 tmp = tmp * 8 + (*ptr++ -
'0');
785 else if (*ptr ==
'_')
789 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'7')
796 else if (ptr[0] ==
'0' && (ptr[1] ==
'b' || ptr[1] ==
'B'))
798 firstdigit = ptr += 2;
802 if (*ptr >=
'0' && *ptr <=
'1')
807 tmp = tmp * 2 + (*ptr++ -
'0');
809 else if (*ptr ==
'_')
813 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'1')
826 if (*ptr >=
'0' && *ptr <=
'9')
831 tmp = tmp * 10 + (*ptr++ -
'0');
833 else if (*ptr ==
'_')
840 if (*ptr ==
'\0' || !isdigit((
unsigned char) *ptr))
853 while (isspace((
unsigned char) *ptr))
864 return -((int64) tmp);
874 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
875 errmsg(
"value \"%s\" is out of range for type %s",
880 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
881 errmsg(
"invalid input syntax for type %s: \"%s\"",
909 cvt = strtoul(s, &endptr, 0);
917 if ((errno && errno != ERANGE) || endptr == s)
919 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
920 errmsg(
"invalid input syntax for type %s: \"%s\"",
925 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
926 errmsg(
"value \"%s\" is out of range for type %s",
937 while (*endptr && isspace((
unsigned char) *endptr))
941 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
942 errmsg(
"invalid input syntax for type %s: \"%s\"",
960 #if PG_UINT32_MAX != ULONG_MAX
961 if (cvt != (
unsigned long) result &&
962 cvt != (
unsigned long) ((
int) result))
964 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
965 errmsg(
"value \"%s\" is out of range for type %s",
1003 if ((errno && errno != ERANGE) || endptr == s)
1005 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1006 errmsg(
"invalid input syntax for type %s: \"%s\"",
1009 if (errno == ERANGE)
1011 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1012 errmsg(
"value \"%s\" is out of range for type %s",
1023 while (*endptr && isspace((
unsigned char) *endptr))
1027 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1028 errmsg(
"invalid input syntax for type %s: \"%s\"",
1073 while (
value >= 10000)
1076 const uint32 c0 = (
c % 100) << 1;
1077 const uint32 c1 = (
c / 100) << 1;
1079 char *pos =
a + olength -
i;
1091 char *pos =
a + olength -
i;
1102 char *pos =
a + olength -
i;
1108 *
a = (char) (
'0' +
value);
1130 uvalue = (
uint32) 0 - uvalue;
1159 while (
value >= 100000000)
1161 const uint64 q =
value / 100000000;
1164 const uint32 c = value3 % 10000;
1165 const uint32 d = value3 / 10000;
1166 const uint32 c0 = (
c % 100) << 1;
1167 const uint32 c1 = (
c / 100) << 1;
1168 const uint32 d0 = (d % 100) << 1;
1169 const uint32 d1 = (d / 100) << 1;
1171 char *pos =
a + olength -
i;
1185 if (value2 >= 10000)
1187 const uint32 c = value2 - 10000 * (value2 / 10000);
1188 const uint32 c0 = (
c % 100) << 1;
1189 const uint32 c1 = (
c / 100) << 1;
1191 char *pos =
a + olength -
i;
1201 const uint32 c = (value2 % 100) << 1;
1202 char *pos =
a + olength -
i;
1212 char *pos =
a + olength -
i;
1217 *
a = (char) (
'0' + value2);
1232 uint64 uvalue =
value;
1237 uvalue = (uint64) 0 - uvalue;
1276 if (
value < 100 && minwidth == 2)
1283 if (
len >= minwidth)
1287 memset(
str,
'0', minwidth -
len);
1288 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)