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]);
106 while (
likely(*ptr) && isspace((
unsigned char) *ptr))
115 else if (*ptr ==
'+')
119 if (
unlikely(!isdigit((
unsigned char) *ptr)))
123 while (*ptr && isdigit((
unsigned char) *ptr))
125 int8 digit = (*ptr++ -
'0');
133 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
151 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
152 errmsg(
"value \"%s\" is out of range for type %s",
157 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
158 errmsg(
"invalid input syntax for type %s: \"%s\"",
182 while (
likely(*ptr) && isspace((
unsigned char) *ptr))
191 else if (*ptr ==
'+')
195 if (
unlikely(!isdigit((
unsigned char) *ptr)))
199 while (*ptr && isdigit((
unsigned char) *ptr))
201 int8 digit = (*ptr++ -
'0');
209 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
227 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
228 errmsg(
"value \"%s\" is out of range for type %s",
233 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
234 errmsg(
"invalid input syntax for type %s: \"%s\"",
266 while (*ptr && isspace((
unsigned char) *ptr))
275 else if (*ptr ==
'+')
279 if (
unlikely(!isdigit((
unsigned char) *ptr)))
283 while (*ptr && isdigit((
unsigned char) *ptr))
285 int8 digit = (*ptr++ -
'0');
293 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
311 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
312 errmsg(
"value \"%s\" is out of range for type %s",
317 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
318 errmsg(
"invalid input syntax for type %s: \"%s\"",
362 while (
value >= 10000)
365 const uint32 c0 = (
c % 100) << 1;
366 const uint32 c1 = (
c / 100) << 1;
368 char *pos =
a + olength -
i;
380 char *pos =
a + olength -
i;
391 char *pos =
a + olength -
i;
397 *
a = (char) (
'0' +
value);
419 uvalue = (
uint32) 0 - uvalue;
448 while (
value >= 100000000)
450 const uint64 q =
value / 100000000;
453 const uint32 c = value2 % 10000;
454 const uint32 d = value2 / 10000;
455 const uint32 c0 = (
c % 100) << 1;
456 const uint32 c1 = (
c / 100) << 1;
457 const uint32 d0 = (d % 100) << 1;
458 const uint32 d1 = (d / 100) << 1;
460 char *pos =
a + olength -
i;
476 const uint32 c = value2 - 10000 * (value2 / 10000);
477 const uint32 c0 = (
c % 100) << 1;
478 const uint32 c1 = (
c / 100) << 1;
480 char *pos =
a + olength -
i;
490 const uint32 c = (value2 % 100) << 1;
491 char *pos =
a + olength -
i;
501 char *pos =
a + olength -
i;
506 *
a = (char) (
'0' + value2);
521 uint64 uvalue =
value;
526 uvalue = (uint64) 0 - uvalue;
565 if (
value < 100 && minwidth == 2)
576 memset(
str,
'0', minwidth -
len);
577 return str + minwidth;
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
static bool pg_sub_s16_overflow(int16 a, int16 b, int16 *result)
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
static bool pg_mul_s16_overflow(int16 a, int16 b, int16 *result)
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
Assert(fmt[strlen(fmt) - 1] !='\n')
int64 pg_strtoint64(const char *s)
int pg_ltoa(int32 value, char *a)
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)
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)
int pg_ultoa_n(uint32 value, char *a)
static int pg_leftmost_one_pos32(uint32 word)
static int pg_leftmost_one_pos64(uint64 word)