42 static const char *
const small[] = {
43 "zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
44 "eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
45 "fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen",
"twenty",
46 "thirty",
"forty",
"fifty",
"sixty",
"seventy",
"eighty",
"ninety"
48 const char *
const *big = small + 18;
66 if (
value % 10 == 0 && tu > 10)
68 small[
value / 100], big[tu / 10]);
71 small[
value / 100], small[tu]);
74 small[
value / 100], big[tu / 10], small[tu % 10]);
79 if (
value % 10 == 0 && tu > 10)
84 sprintf(
buf,
"%s %s", big[tu / 10], small[tu % 10]);
97 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
98 errmsg(
"money out of range")));
110 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
111 errmsg(
"money out of range")));
123 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
124 errmsg(
"money out of range")));
136 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
137 errmsg(
"money out of range")));
149 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
150 errmsg(
"money out of range")));
160 (
errcode(ERRCODE_DIVISION_BY_ZERO),
161 errmsg(
"division by zero")));
176 Node *escontext = fcinfo->context;
181 bool seen_dot =
false;
201 fpoint = lconvert->frac_digits;
202 if (fpoint < 0 || fpoint > 10)
206 if (*lconvert->mon_decimal_point !=
'\0' &&
207 lconvert->mon_decimal_point[1] ==
'\0')
208 dsymbol = *lconvert->mon_decimal_point;
211 if (*lconvert->mon_thousands_sep !=
'\0')
212 ssymbol = lconvert->mon_thousands_sep;
214 ssymbol = (dsymbol !=
',') ?
"," :
".";
215 csymbol = (*lconvert->currency_symbol !=
'\0') ? lconvert->currency_symbol :
"$";
216 psymbol = (*lconvert->positive_sign !=
'\0') ? lconvert->positive_sign :
"+";
217 nsymbol = (*lconvert->negative_sign !=
'\0') ? lconvert->negative_sign :
"-";
220 printf(
"cashin- precision '%d'; decimal '%c'; thousands '%s'; currency '%s'; positive '%s'; negative '%s'\n",
221 fpoint, dsymbol, ssymbol, csymbol, psymbol, nsymbol);
226 while (isspace((
unsigned char) *s))
228 if (strncmp(s, csymbol, strlen(csymbol)) == 0)
229 s += strlen(csymbol);
230 while (isspace((
unsigned char) *s))
234 printf(
"cashin- string is '%s'\n", s);
240 if (strncmp(s, nsymbol, strlen(nsymbol)) == 0)
243 s += strlen(nsymbol);
250 else if (strncmp(s, psymbol, strlen(psymbol)) == 0)
251 s += strlen(psymbol);
254 printf(
"cashin- string is '%s'\n", s);
258 while (isspace((
unsigned char) *s))
260 if (strncmp(s, csymbol, strlen(csymbol)) == 0)
261 s += strlen(csymbol);
262 while (isspace((
unsigned char) *s))
266 printf(
"cashin- string is '%s'\n", s);
284 if (isdigit((
unsigned char) *s) && (!seen_dot || dec < fpoint))
286 int8 digit = *s -
'0';
291 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
292 errmsg(
"value \"%s\" is out of range for type %s",
299 else if (*s == dsymbol && !seen_dot)
304 else if (strncmp(s, ssymbol, strlen(ssymbol)) == 0)
305 s += strlen(ssymbol) - 1;
311 if (isdigit((
unsigned char) *s) && *s >=
'5')
316 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
317 errmsg(
"value \"%s\" is out of range for type %s",
322 for (; dec < fpoint; dec++)
326 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
327 errmsg(
"value \"%s\" is out of range for type %s",
335 while (isdigit((
unsigned char) *s))
340 if (isspace((
unsigned char) *s) || *s ==
')')
342 else if (strncmp(s, nsymbol, strlen(nsymbol)) == 0)
345 s += strlen(nsymbol);
347 else if (strncmp(s, psymbol, strlen(psymbol)) == 0)
348 s += strlen(psymbol);
349 else if (strncmp(s, csymbol, strlen(csymbol)) == 0)
350 s += strlen(csymbol);
353 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
354 errmsg(
"invalid input syntax for type %s: \"%s\"",
366 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
367 errmsg(
"value \"%s\" is out of range for type %s",
406 points = lconvert->frac_digits;
407 if (points < 0 || points > 10)
414 mon_group = *lconvert->mon_grouping;
415 if (mon_group <= 0 || mon_group > 6)
419 if (*lconvert->mon_decimal_point !=
'\0' &&
420 lconvert->mon_decimal_point[1] ==
'\0')
421 dsymbol = *lconvert->mon_decimal_point;
424 if (*lconvert->mon_thousands_sep !=
'\0')
425 ssymbol = lconvert->mon_thousands_sep;
427 ssymbol = (dsymbol !=
',') ?
"," :
".";
428 csymbol = (*lconvert->currency_symbol !=
'\0') ? lconvert->currency_symbol :
"$";
435 signsymbol = (*lconvert->negative_sign !=
'\0') ? lconvert->negative_sign :
"-";
436 sign_posn = lconvert->n_sign_posn;
437 cs_precedes = lconvert->n_cs_precedes;
438 sep_by_space = lconvert->n_sep_by_space;
442 signsymbol = lconvert->positive_sign;
443 sign_posn = lconvert->p_sign_posn;
444 cs_precedes = lconvert->p_cs_precedes;
445 sep_by_space = lconvert->p_sep_by_space;
449 bufptr =
buf +
sizeof(
buf) - 1;
461 if (points && digit_pos == 0)
464 *(--bufptr) = dsymbol;
466 else if (digit_pos < 0 && (digit_pos % mon_group) == 0)
469 bufptr -= strlen(ssymbol);
470 memcpy(bufptr, ssymbol, strlen(ssymbol));
473 *(--bufptr) = ((uint64)
value % 10) +
'0';
476 }
while (
value || digit_pos >= 0);
508 (sep_by_space == 1) ?
" " :
"",
513 (sep_by_space == 1) ?
" " :
"",
521 (sep_by_space == 2) ?
" " :
"",
523 (sep_by_space == 1) ?
" " :
"",
528 (sep_by_space == 2) ?
" " :
"",
530 (sep_by_space == 1) ?
" " :
"",
537 (sep_by_space == 1) ?
" " :
"",
539 (sep_by_space == 2) ?
" " :
"",
544 (sep_by_space == 1) ?
" " :
"",
546 (sep_by_space == 2) ?
" " :
"",
553 (sep_by_space == 2) ?
" " :
"",
555 (sep_by_space == 1) ?
" " :
"",
560 (sep_by_space == 1) ?
" " :
"",
562 (sep_by_space == 2) ?
" " :
"",
569 (sep_by_space == 2) ?
" " :
"",
571 (sep_by_space == 1) ?
" " :
"",
576 (sep_by_space == 1) ?
" " :
"",
578 (sep_by_space == 2) ?
" " :
"",
722 (
errcode(ERRCODE_DIVISION_BY_ZERO),
723 errmsg(
"division by zero")));
934 result = (c1 > c2) ? c1 : c2;
949 result = (c1 < c2) ? c1 : c2;
977 strcpy(
buf,
"minus ");
986 m0 =
val % INT64CONST(100);
987 m1 = (
val / INT64CONST(100)) % 1000;
988 m2 = (
val / INT64CONST(100000)) % 1000;
989 m3 = (
val / INT64CONST(100000000)) % 1000;
990 m4 = (
val / INT64CONST(100000000000)) % 1000;
991 m5 = (
val / INT64CONST(100000000000000)) % 1000;
992 m6 = (
val / INT64CONST(100000000000000000)) % 1000;
997 strcat(
buf,
" quadrillion ");
1003 strcat(
buf,
" trillion ");
1009 strcat(
buf,
" billion ");
1015 strcat(
buf,
" million ");
1021 strcat(
buf,
" thousand ");
1028 strcat(
buf,
"zero");
1030 strcat(
buf, (
val / 100) == 1 ?
" dollar and " :
" dollars and ");
1032 strcat(
buf, m0 == 1 ?
" cent" :
" cents");
1054 fpoint = lconvert->frac_digits;
1055 if (fpoint < 0 || fpoint > 10)
1071 for (
i = 0;
i < fpoint;
i++)
1113 fpoint = lconvert->frac_digits;
1114 if (fpoint < 0 || fpoint > 10)
1119 for (
i = 0;
i < fpoint;
i++)
1146 fpoint = lconvert->frac_digits;
1147 if (fpoint < 0 || fpoint > 10)
1152 for (
i = 0;
i < fpoint;
i++)
1176 fpoint = lconvert->frac_digits;
1177 if (fpoint < 0 || fpoint > 10)
1182 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)
#define FLOAT8_FITS_IN_INT64(num)
Datum int8_cash(PG_FUNCTION_ARGS)
Datum cash_mul_int8(PG_FUNCTION_ARGS)
Datum flt8_mul_cash(PG_FUNCTION_ARGS)
static Cash cash_mi_cash(Cash c1, Cash c2)
Datum cash_mi(PG_FUNCTION_ARGS)
Datum flt4_mul_cash(PG_FUNCTION_ARGS)
Datum cash_numeric(PG_FUNCTION_ARGS)
static Cash cash_div_int64(Cash c, int64 i)
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)
static Cash cash_mul_int64(Cash c, int64 i)
static Cash cash_mul_float8(Cash c, float8 f)
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)
static Cash cash_div_float8(Cash c, float8 f)
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)
static Cash cash_pl_cash(Cash c1, Cash c2)
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)
static void PGresult * res
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
static float8 float8_mul(const float8 val1, const float8 val2)
static float8 float8_div(const float8 val1, const float8 val2)
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)
static bool pg_add_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)