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;
156 digit = (*ptr -
'0');
176 digit = (*ptr -
'0');
186 tmp = tmp * 10 + digit;
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))
349 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
350 errmsg(
"value \"%s\" is out of range for type %s",
355 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
356 errmsg(
"invalid input syntax for type %s: \"%s\"",
392 const char *firstdigit;
417 digit = (*ptr -
'0');
437 digit = (*ptr -
'0');
447 tmp = tmp * 10 + digit;
472 while (isspace((
unsigned char) *ptr))
481 else if (*ptr ==
'+')
485 if (ptr[0] ==
'0' && (ptr[1] ==
'x' || ptr[1] ==
'X'))
487 firstdigit = ptr += 2;
491 if (isxdigit((
unsigned char) *ptr))
496 tmp = tmp * 16 +
hexlookup[(
unsigned char) *ptr++];
498 else if (*ptr ==
'_')
502 if (*ptr ==
'\0' || !isxdigit((
unsigned char) *ptr))
509 else if (ptr[0] ==
'0' && (ptr[1] ==
'o' || ptr[1] ==
'O'))
511 firstdigit = ptr += 2;
515 if (*ptr >=
'0' && *ptr <=
'7')
520 tmp = tmp * 8 + (*ptr++ -
'0');
522 else if (*ptr ==
'_')
526 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'7')
533 else if (ptr[0] ==
'0' && (ptr[1] ==
'b' || ptr[1] ==
'B'))
535 firstdigit = ptr += 2;
539 if (*ptr >=
'0' && *ptr <=
'1')
544 tmp = tmp * 2 + (*ptr++ -
'0');
546 else if (*ptr ==
'_')
550 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'1')
563 if (*ptr >=
'0' && *ptr <=
'9')
568 tmp = tmp * 10 + (*ptr++ -
'0');
570 else if (*ptr ==
'_')
577 if (*ptr ==
'\0' || !isdigit((
unsigned char) *ptr))
590 while (isspace((
unsigned char) *ptr))
610 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
611 errmsg(
"value \"%s\" is out of range for type %s",
616 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
617 errmsg(
"invalid input syntax for type %s: \"%s\"",
653 const char *firstdigit;
678 digit = (*ptr -
'0');
698 digit = (*ptr -
'0');
708 tmp = tmp * 10 + digit;
733 while (isspace((
unsigned char) *ptr))
742 else if (*ptr ==
'+')
746 if (ptr[0] ==
'0' && (ptr[1] ==
'x' || ptr[1] ==
'X'))
748 firstdigit = ptr += 2;
752 if (isxdigit((
unsigned char) *ptr))
757 tmp = tmp * 16 +
hexlookup[(
unsigned char) *ptr++];
759 else if (*ptr ==
'_')
763 if (*ptr ==
'\0' || !isxdigit((
unsigned char) *ptr))
770 else if (ptr[0] ==
'0' && (ptr[1] ==
'o' || ptr[1] ==
'O'))
772 firstdigit = ptr += 2;
776 if (*ptr >=
'0' && *ptr <=
'7')
781 tmp = tmp * 8 + (*ptr++ -
'0');
783 else if (*ptr ==
'_')
787 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'7')
794 else if (ptr[0] ==
'0' && (ptr[1] ==
'b' || ptr[1] ==
'B'))
796 firstdigit = ptr += 2;
800 if (*ptr >=
'0' && *ptr <=
'1')
805 tmp = tmp * 2 + (*ptr++ -
'0');
807 else if (*ptr ==
'_')
811 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'1')
824 if (*ptr >=
'0' && *ptr <=
'9')
829 tmp = tmp * 10 + (*ptr++ -
'0');
831 else if (*ptr ==
'_')
838 if (*ptr ==
'\0' || !isdigit((
unsigned char) *ptr))
851 while (isspace((
unsigned char) *ptr))
871 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
872 errmsg(
"value \"%s\" is out of range for type %s",
877 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
878 errmsg(
"invalid input syntax for type %s: \"%s\"",
906 cvt = strtoul(s, &endptr, 0);
914 if ((errno && errno != ERANGE) || endptr == s)
916 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
917 errmsg(
"invalid input syntax for type %s: \"%s\"",
922 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
923 errmsg(
"value \"%s\" is out of range for type %s",
934 while (*endptr && isspace((
unsigned char) *endptr))
938 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
939 errmsg(
"invalid input syntax for type %s: \"%s\"",
957 #if PG_UINT32_MAX != ULONG_MAX
958 if (cvt != (
unsigned long) result &&
959 cvt != (
unsigned long) ((
int) result))
961 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
962 errmsg(
"value \"%s\" is out of range for type %s",
1000 if ((errno && errno != ERANGE) || endptr == s)
1002 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1003 errmsg(
"invalid input syntax for type %s: \"%s\"",
1006 if (errno == ERANGE)
1008 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1009 errmsg(
"value \"%s\" is out of range for type %s",
1020 while (*endptr && isspace((
unsigned char) *endptr))
1024 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1025 errmsg(
"invalid input syntax for type %s: \"%s\"",
1070 while (
value >= 10000)
1073 const uint32 c0 = (
c % 100) << 1;
1074 const uint32 c1 = (
c / 100) << 1;
1076 char *pos =
a + olength -
i;
1088 char *pos =
a + olength -
i;
1099 char *pos =
a + olength -
i;
1105 *
a = (char) (
'0' +
value);
1127 uvalue = (
uint32) 0 - uvalue;
1156 while (
value >= 100000000)
1158 const uint64 q =
value / 100000000;
1161 const uint32 c = value3 % 10000;
1162 const uint32 d = value3 / 10000;
1163 const uint32 c0 = (
c % 100) << 1;
1164 const uint32 c1 = (
c / 100) << 1;
1165 const uint32 d0 = (d % 100) << 1;
1166 const uint32 d1 = (d / 100) << 1;
1168 char *pos =
a + olength -
i;
1182 if (value2 >= 10000)
1184 const uint32 c = value2 - 10000 * (value2 / 10000);
1185 const uint32 c0 = (
c % 100) << 1;
1186 const uint32 c1 = (
c / 100) << 1;
1188 char *pos =
a + olength -
i;
1198 const uint32 c = (value2 % 100) << 1;
1199 char *pos =
a + olength -
i;
1209 char *pos =
a + olength -
i;
1214 *
a = (char) (
'0' + value2);
1229 uint64 uvalue =
value;
1234 uvalue = (uint64) 0 - uvalue;
1273 if (
value < 100 && minwidth == 2)
1280 if (
len >= minwidth)
1284 memset(
str,
'0', minwidth -
len);
1285 return str + minwidth;
#define Assert(condition)
#define strtou64(str, endptr, base)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
static bool pg_neg_u32_overflow(uint32 a, int32 *result)
static bool pg_neg_u16_overflow(uint16 a, int16 *result)
static bool pg_neg_u64_overflow(uint64 a, int64 *result)
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)