29 "00" "01" "02" "03" "04" "05" "06" "07" "08" "09"
30 "10" "11" "12" "13" "14" "15" "16" "17" "18" "19"
31 "20" "21" "22" "23" "24" "25" "26" "27" "28" "29"
32 "30" "31" "32" "33" "34" "35" "36" "37" "38" "39"
33 "40" "41" "42" "43" "44" "45" "46" "47" "48" "49"
34 "50" "51" "52" "53" "54" "55" "56" "57" "58" "59"
35 "60" "61" "62" "63" "64" "65" "66" "67" "68" "69"
36 "70" "71" "72" "73" "74" "75" "76" "77" "78" "79"
37 "80" "81" "82" "83" "84" "85" "86" "87" "88" "89"
38 "90" "91" "92" "93" "94" "95" "96" "97" "98" "99";
47 static const uint32 PowersOfTen[] = {
50 1000000, 10000000, 100000000,
59 return t + (v >= PowersOfTen[t]);
66 static const uint64 PowersOfTen[] = {
67 UINT64CONST(1), UINT64CONST(10),
68 UINT64CONST(100), UINT64CONST(1000),
69 UINT64CONST(10000), UINT64CONST(100000),
70 UINT64CONST(1000000), UINT64CONST(10000000),
71 UINT64CONST(100000000), UINT64CONST(1000000000),
72 UINT64CONST(10000000000), UINT64CONST(100000000000),
73 UINT64CONST(1000000000000), UINT64CONST(10000000000000),
74 UINT64CONST(100000000000000), UINT64CONST(1000000000000000),
75 UINT64CONST(10000000000000000), UINT64CONST(100000000000000000),
76 UINT64CONST(1000000000000000000), UINT64CONST(10000000000000000000)
84 return t + (v >= PowersOfTen[t]);
88 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
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 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
92 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
93 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
94 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
95 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
130 const char *firstdigit;
154 digit = (*ptr -
'0');
174 digit = (*ptr -
'0');
184 tmp = tmp * 10 + digit;
196 return -((
int16) tmp);
210 while (isspace((
unsigned char) *ptr))
219 else if (*ptr ==
'+')
223 if (ptr[0] ==
'0' && (ptr[1] ==
'x' || ptr[1] ==
'X'))
225 firstdigit = ptr += 2;
229 if (isxdigit((
unsigned char) *ptr))
234 tmp = tmp * 16 +
hexlookup[(
unsigned char) *ptr++];
236 else if (*ptr ==
'_')
240 if (*ptr ==
'\0' || !isxdigit((
unsigned char) *ptr))
247 else if (ptr[0] ==
'0' && (ptr[1] ==
'o' || ptr[1] ==
'O'))
249 firstdigit = ptr += 2;
253 if (*ptr >=
'0' && *ptr <=
'7')
258 tmp = tmp * 8 + (*ptr++ -
'0');
260 else if (*ptr ==
'_')
264 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'7')
271 else if (ptr[0] ==
'0' && (ptr[1] ==
'b' || ptr[1] ==
'B'))
273 firstdigit = ptr += 2;
277 if (*ptr >=
'0' && *ptr <=
'1')
282 tmp = tmp * 2 + (*ptr++ -
'0');
284 else if (*ptr ==
'_')
288 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'1')
301 if (*ptr >=
'0' && *ptr <=
'9')
306 tmp = tmp * 10 + (*ptr++ -
'0');
308 else if (*ptr ==
'_')
315 if (*ptr ==
'\0' || !isdigit((
unsigned char) *ptr))
328 while (isspace((
unsigned char) *ptr))
339 return -((
int16) tmp);
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;
416 digit = (*ptr -
'0');
436 digit = (*ptr -
'0');
446 tmp = tmp * 10 + digit;
458 return -((
int32) tmp);
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))
601 return -((
int32) tmp);
611 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
612 errmsg(
"value \"%s\" is out of range for type %s",
617 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
618 errmsg(
"invalid input syntax for type %s: \"%s\"",
654 const char *firstdigit;
678 digit = (*ptr -
'0');
698 digit = (*ptr -
'0');
708 tmp = tmp * 10 + digit;
720 return -((int64) tmp);
734 while (isspace((
unsigned char) *ptr))
743 else if (*ptr ==
'+')
747 if (ptr[0] ==
'0' && (ptr[1] ==
'x' || ptr[1] ==
'X'))
749 firstdigit = ptr += 2;
753 if (isxdigit((
unsigned char) *ptr))
758 tmp = tmp * 16 +
hexlookup[(
unsigned char) *ptr++];
760 else if (*ptr ==
'_')
764 if (*ptr ==
'\0' || !isxdigit((
unsigned char) *ptr))
771 else if (ptr[0] ==
'0' && (ptr[1] ==
'o' || ptr[1] ==
'O'))
773 firstdigit = ptr += 2;
777 if (*ptr >=
'0' && *ptr <=
'7')
782 tmp = tmp * 8 + (*ptr++ -
'0');
784 else if (*ptr ==
'_')
788 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'7')
795 else if (ptr[0] ==
'0' && (ptr[1] ==
'b' || ptr[1] ==
'B'))
797 firstdigit = ptr += 2;
801 if (*ptr >=
'0' && *ptr <=
'1')
806 tmp = tmp * 2 + (*ptr++ -
'0');
808 else if (*ptr ==
'_')
812 if (*ptr ==
'\0' || *ptr < '0' || *ptr >
'1')
825 if (*ptr >=
'0' && *ptr <=
'9')
830 tmp = tmp * 10 + (*ptr++ -
'0');
832 else if (*ptr ==
'_')
839 if (*ptr ==
'\0' || !isdigit((
unsigned char) *ptr))
852 while (isspace((
unsigned char) *ptr))
863 return -((int64) tmp);
873 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
874 errmsg(
"value \"%s\" is out of range for type %s",
879 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
880 errmsg(
"invalid input syntax for type %s: \"%s\"",
908 cvt = strtoul(s, &endptr, 0);
916 if ((errno && errno != ERANGE) || endptr == s)
918 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
919 errmsg(
"invalid input syntax for type %s: \"%s\"",
924 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
925 errmsg(
"value \"%s\" is out of range for type %s",
936 while (*endptr && isspace((
unsigned char) *endptr))
940 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
941 errmsg(
"invalid input syntax for type %s: \"%s\"",
959 #if PG_UINT32_MAX != ULONG_MAX
960 if (cvt != (
unsigned long) result &&
961 cvt != (
unsigned long) ((
int) result))
963 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
964 errmsg(
"value \"%s\" is out of range for type %s",
1002 if ((errno && errno != ERANGE) || endptr == s)
1004 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1005 errmsg(
"invalid input syntax for type %s: \"%s\"",
1008 if (errno == ERANGE)
1010 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1011 errmsg(
"value \"%s\" is out of range for type %s",
1022 while (*endptr && isspace((
unsigned char) *endptr))
1026 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1027 errmsg(
"invalid input syntax for type %s: \"%s\"",
1072 while (
value >= 10000)
1075 const uint32 c0 = (
c % 100) << 1;
1076 const uint32 c1 = (
c / 100) << 1;
1078 char *pos =
a + olength -
i;
1090 char *pos =
a + olength -
i;
1101 char *pos =
a + olength -
i;
1107 *
a = (char) (
'0' +
value);
1129 uvalue = (
uint32) 0 - uvalue;
1158 while (
value >= 100000000)
1160 const uint64 q =
value / 100000000;
1163 const uint32 c = value3 % 10000;
1164 const uint32 d = value3 / 10000;
1165 const uint32 c0 = (
c % 100) << 1;
1166 const uint32 c1 = (
c / 100) << 1;
1167 const uint32 d0 = (d % 100) << 1;
1168 const uint32 d1 = (d / 100) << 1;
1170 char *pos =
a + olength -
i;
1184 if (value2 >= 10000)
1186 const uint32 c = value2 - 10000 * (value2 / 10000);
1187 const uint32 c0 = (
c % 100) << 1;
1188 const uint32 c1 = (
c / 100) << 1;
1190 char *pos =
a + olength -
i;
1200 const uint32 c = (value2 % 100) << 1;
1201 char *pos =
a + olength -
i;
1211 char *pos =
a + olength -
i;
1216 *
a = (char) (
'0' + value2);
1231 uint64 uvalue =
value;
1236 uvalue = (uint64) 0 - uvalue;
1275 if (
value < 100 && minwidth == 2)
1282 if (
len >= minwidth)
1286 memset(
str,
'0', minwidth -
len);
1287 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)