41 static const char *
const small[] = {
42 "zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
43 "eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
44 "fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen",
"twenty",
45 "thirty",
"forty",
"fifty",
"sixty",
"seventy",
"eighty",
"ninety"
47 const char *
const *big = small + 18;
65 if (
value % 10 == 0 && tu > 10)
67 small[
value / 100], big[tu / 10]);
70 small[
value / 100], small[tu]);
73 small[
value / 100], big[tu / 10], small[tu % 10]);
78 if (
value % 10 == 0 && tu > 10)
83 sprintf(
buf,
"%s %s", big[tu / 10], small[tu % 10]);
99 Node *escontext = fcinfo->context;
104 bool seen_dot =
false;
124 fpoint = lconvert->frac_digits;
125 if (fpoint < 0 || fpoint > 10)
129 if (*lconvert->mon_decimal_point !=
'\0' &&
130 lconvert->mon_decimal_point[1] ==
'\0')
131 dsymbol = *lconvert->mon_decimal_point;
134 if (*lconvert->mon_thousands_sep !=
'\0')
135 ssymbol = lconvert->mon_thousands_sep;
137 ssymbol = (dsymbol !=
',') ?
"," :
".";
138 csymbol = (*lconvert->currency_symbol !=
'\0') ? lconvert->currency_symbol :
"$";
139 psymbol = (*lconvert->positive_sign !=
'\0') ? lconvert->positive_sign :
"+";
140 nsymbol = (*lconvert->negative_sign !=
'\0') ? lconvert->negative_sign :
"-";
143 printf(
"cashin- precision '%d'; decimal '%c'; thousands '%s'; currency '%s'; positive '%s'; negative '%s'\n",
144 fpoint, dsymbol, ssymbol, csymbol, psymbol, nsymbol);
149 while (isspace((
unsigned char) *s))
151 if (strncmp(s, csymbol, strlen(csymbol)) == 0)
152 s += strlen(csymbol);
153 while (isspace((
unsigned char) *s))
157 printf(
"cashin- string is '%s'\n", s);
163 if (strncmp(s, nsymbol, strlen(nsymbol)) == 0)
166 s += strlen(nsymbol);
173 else if (strncmp(s, psymbol, strlen(psymbol)) == 0)
174 s += strlen(psymbol);
177 printf(
"cashin- string is '%s'\n", s);
181 while (isspace((
unsigned char) *s))
183 if (strncmp(s, csymbol, strlen(csymbol)) == 0)
184 s += strlen(csymbol);
185 while (isspace((
unsigned char) *s))
189 printf(
"cashin- string is '%s'\n", s);
207 if (isdigit((
unsigned char) *s) && (!seen_dot || dec < fpoint))
209 int8 digit = *s -
'0';
214 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
215 errmsg(
"value \"%s\" is out of range for type %s",
222 else if (*s == dsymbol && !seen_dot)
227 else if (strncmp(s, ssymbol, strlen(ssymbol)) == 0)
228 s += strlen(ssymbol) - 1;
234 if (isdigit((
unsigned char) *s) && *s >=
'5')
239 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
240 errmsg(
"value \"%s\" is out of range for type %s",
245 for (; dec < fpoint; dec++)
249 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
250 errmsg(
"value \"%s\" is out of range for type %s",
258 while (isdigit((
unsigned char) *s))
263 if (isspace((
unsigned char) *s) || *s ==
')')
265 else if (strncmp(s, nsymbol, strlen(nsymbol)) == 0)
268 s += strlen(nsymbol);
270 else if (strncmp(s, psymbol, strlen(psymbol)) == 0)
271 s += strlen(psymbol);
272 else if (strncmp(s, csymbol, strlen(csymbol)) == 0)
273 s += strlen(csymbol);
276 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
277 errmsg(
"invalid input syntax for type %s: \"%s\"",
289 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
290 errmsg(
"value \"%s\" is out of range for type %s",
329 points = lconvert->frac_digits;
330 if (points < 0 || points > 10)
337 mon_group = *lconvert->mon_grouping;
338 if (mon_group <= 0 || mon_group > 6)
342 if (*lconvert->mon_decimal_point !=
'\0' &&
343 lconvert->mon_decimal_point[1] ==
'\0')
344 dsymbol = *lconvert->mon_decimal_point;
347 if (*lconvert->mon_thousands_sep !=
'\0')
348 ssymbol = lconvert->mon_thousands_sep;
350 ssymbol = (dsymbol !=
',') ?
"," :
".";
351 csymbol = (*lconvert->currency_symbol !=
'\0') ? lconvert->currency_symbol :
"$";
358 signsymbol = (*lconvert->negative_sign !=
'\0') ? lconvert->negative_sign :
"-";
359 sign_posn = lconvert->n_sign_posn;
360 cs_precedes = lconvert->n_cs_precedes;
361 sep_by_space = lconvert->n_sep_by_space;
365 signsymbol = lconvert->positive_sign;
366 sign_posn = lconvert->p_sign_posn;
367 cs_precedes = lconvert->p_cs_precedes;
368 sep_by_space = lconvert->p_sep_by_space;
372 bufptr =
buf +
sizeof(
buf) - 1;
384 if (points && digit_pos == 0)
387 *(--bufptr) = dsymbol;
389 else if (digit_pos < 0 && (digit_pos % mon_group) == 0)
392 bufptr -= strlen(ssymbol);
393 memcpy(bufptr, ssymbol, strlen(ssymbol));
396 *(--bufptr) = ((uint64)
value % 10) +
'0';
399 }
while (
value || digit_pos >= 0);
431 (sep_by_space == 1) ?
" " :
"",
436 (sep_by_space == 1) ?
" " :
"",
444 (sep_by_space == 2) ?
" " :
"",
446 (sep_by_space == 1) ?
" " :
"",
451 (sep_by_space == 2) ?
" " :
"",
453 (sep_by_space == 1) ?
" " :
"",
460 (sep_by_space == 1) ?
" " :
"",
462 (sep_by_space == 2) ?
" " :
"",
467 (sep_by_space == 1) ?
" " :
"",
469 (sep_by_space == 2) ?
" " :
"",
476 (sep_by_space == 2) ?
" " :
"",
478 (sep_by_space == 1) ?
" " :
"",
483 (sep_by_space == 1) ?
" " :
"",
485 (sep_by_space == 2) ?
" " :
"",
492 (sep_by_space == 2) ?
" " :
"",
494 (sep_by_space == 1) ?
" " :
"",
499 (sep_by_space == 1) ?
" " :
"",
501 (sep_by_space == 2) ?
" " :
"",
651 (
errcode(ERRCODE_DIVISION_BY_ZERO),
652 errmsg(
"division by zero")));
669 result = rint(
c * f);
684 result = rint(f *
c);
701 (
errcode(ERRCODE_DIVISION_BY_ZERO),
702 errmsg(
"division by zero")));
704 result = rint(
c / f);
752 (
errcode(ERRCODE_DIVISION_BY_ZERO),
753 errmsg(
"division by zero")));
801 (
errcode(ERRCODE_DIVISION_BY_ZERO),
802 errmsg(
"division by zero")));
853 (
errcode(ERRCODE_DIVISION_BY_ZERO),
854 errmsg(
"division by zero")));
903 (
errcode(ERRCODE_DIVISION_BY_ZERO),
904 errmsg(
"division by zero")));
920 result = (c1 > c2) ? c1 : c2;
935 result = (c1 < c2) ? c1 : c2;
963 strcpy(
buf,
"minus ");
972 m0 =
val % INT64CONST(100);
973 m1 = (
val / INT64CONST(100)) % 1000;
974 m2 = (
val / INT64CONST(100000)) % 1000;
975 m3 = (
val / INT64CONST(100000000)) % 1000;
976 m4 = (
val / INT64CONST(100000000000)) % 1000;
977 m5 = (
val / INT64CONST(100000000000000)) % 1000;
978 m6 = (
val / INT64CONST(100000000000000000)) % 1000;
983 strcat(
buf,
" quadrillion ");
989 strcat(
buf,
" trillion ");
995 strcat(
buf,
" billion ");
1001 strcat(
buf,
" million ");
1007 strcat(
buf,
" thousand ");
1014 strcat(
buf,
"zero");
1016 strcat(
buf, (
val / 100) == 1 ?
" dollar and " :
" dollars and ");
1018 strcat(
buf, m0 == 1 ?
" cent" :
" cents");
1040 fpoint = lconvert->frac_digits;
1041 if (fpoint < 0 || fpoint > 10)
1057 for (
i = 0;
i < fpoint;
i++)
1099 fpoint = lconvert->frac_digits;
1100 if (fpoint < 0 || fpoint > 10)
1105 for (
i = 0;
i < fpoint;
i++)
1132 fpoint = lconvert->frac_digits;
1133 if (fpoint < 0 || fpoint > 10)
1138 for (
i = 0;
i < fpoint;
i++)
1162 fpoint = lconvert->frac_digits;
1163 if (fpoint < 0 || fpoint > 10)
1168 for (
i = 0;
i < fpoint;
i++)
Datum numeric_div(PG_FUNCTION_ARGS)
Datum numeric_round(PG_FUNCTION_ARGS)
Numeric int64_to_numeric(int64 val)
Datum numeric_int8(PG_FUNCTION_ARGS)
Datum numeric_scale(PG_FUNCTION_ARGS)
Datum numeric_mul(PG_FUNCTION_ARGS)
Datum int8_cash(PG_FUNCTION_ARGS)
Datum cash_mul_int8(PG_FUNCTION_ARGS)
Datum flt8_mul_cash(PG_FUNCTION_ARGS)
Datum cash_mi(PG_FUNCTION_ARGS)
Datum flt4_mul_cash(PG_FUNCTION_ARGS)
Datum cash_numeric(PG_FUNCTION_ARGS)
Datum cash_gt(PG_FUNCTION_ARGS)
Datum cash_div_cash(PG_FUNCTION_ARGS)
Datum cash_mul_flt4(PG_FUNCTION_ARGS)
Datum cash_ne(PG_FUNCTION_ARGS)
Datum cash_out(PG_FUNCTION_ARGS)
Datum cash_ge(PG_FUNCTION_ARGS)
Datum cash_div_int4(PG_FUNCTION_ARGS)
Datum cash_in(PG_FUNCTION_ARGS)
Datum numeric_cash(PG_FUNCTION_ARGS)
Datum cash_pl(PG_FUNCTION_ARGS)
Datum cash_eq(PG_FUNCTION_ARGS)
Datum cash_div_int2(PG_FUNCTION_ARGS)
Datum cash_mul_flt8(PG_FUNCTION_ARGS)
Datum int4_mul_cash(PG_FUNCTION_ARGS)
Datum int2_mul_cash(PG_FUNCTION_ARGS)
Datum cash_div_int8(PG_FUNCTION_ARGS)
Datum cash_lt(PG_FUNCTION_ARGS)
Datum cashlarger(PG_FUNCTION_ARGS)
Datum cash_send(PG_FUNCTION_ARGS)
Datum cash_mul_int4(PG_FUNCTION_ARGS)
Datum cash_recv(PG_FUNCTION_ARGS)
Datum cash_div_flt8(PG_FUNCTION_ARGS)
Datum cashsmaller(PG_FUNCTION_ARGS)
Datum cash_le(PG_FUNCTION_ARGS)
Datum cash_div_flt4(PG_FUNCTION_ARGS)
Datum int8_mul_cash(PG_FUNCTION_ARGS)
Datum cash_cmp(PG_FUNCTION_ARGS)
Datum cash_mul_int2(PG_FUNCTION_ARGS)
Datum int4_cash(PG_FUNCTION_ARGS)
Datum cash_words(PG_FUNCTION_ARGS)
static const char * num_word(Cash value)
#define PG_RETURN_CASH(x)
#define PG_GETARG_CASH(n)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
Datum Int64GetDatum(int64 X)
#define PG_RETURN_BYTEA_P(x)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_GETARG_FLOAT8(n)
#define PG_RETURN_FLOAT8(x)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_RETURN_DATUM(x)
#define PG_GETARG_FLOAT4(n)
#define PG_RETURN_BOOL(x)
#define PG_GETARG_INT16(n)
Datum int8mul(PG_FUNCTION_ARGS)
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
if(TABLE==NULL||TABLE_index==NULL)
static Datum NumericGetDatum(Numeric X)
struct lconv * PGLC_localeconv(void)
unsigned char pg_toupper(unsigned char ch)
static int64 DatumGetInt64(Datum X)
static Datum Int32GetDatum(int32 X)
char * psprintf(const char *fmt,...)
StringInfoData * StringInfo
text * cstring_to_text(const char *s)