Index: src/backend/utils/adt/arrayfuncs.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v retrieving revision 1.72 diff -c -r1.72 arrayfuncs.c *** src/backend/utils/adt/arrayfuncs.c 2001/11/29 21:02:41 1.72 --- src/backend/utils/adt/arrayfuncs.c 2002/02/18 06:55:42 *************** *** 46,58 **** * Local definitions * ---------- */ - #ifndef MIN - #define MIN(a,b) (((a)<(b)) ? (a) : (b)) - #endif - #ifndef MAX - #define MAX(a,b) (((a)>(b)) ? (a) : (b)) - #endif - #define ASSGN "=" #define RETURN_NULL(type) do { *isNull = true; return (type) 0; } while (0) --- 46,51 ---- *************** *** 1222,1229 **** */ int oldlb = ARR_LBOUND(array)[0]; int oldub = oldlb + ARR_DIMS(array)[0] - 1; ! int slicelb = MAX(oldlb, lowerIndx[0]); ! int sliceub = MIN(oldub, upperIndx[0]); char *oldarraydata = ARR_DATA_PTR(array); lenbefore = array_nelems_size(oldarraydata, --- 1215,1222 ---- */ int oldlb = ARR_LBOUND(array)[0]; int oldub = oldlb + ARR_DIMS(array)[0] - 1; ! int slicelb = Max(oldlb, lowerIndx[0]); ! int sliceub = Min(oldub, upperIndx[0]); char *oldarraydata = ARR_DATA_PTR(array); lenbefore = array_nelems_size(oldarraydata, Index: src/backend/utils/adt/formatting.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v retrieving revision 1.49 diff -c -r1.49 formatting.c *** src/backend/utils/adt/formatting.c 2002/01/04 15:49:42 1.49 --- src/backend/utils/adt/formatting.c 2002/02/18 06:55:44 *************** *** 434,450 **** tmtcTzn(_X) = NULL; \ } while(0) - /* ---------- - * Utils - * ---------- - */ - #ifndef MIN - #define MIN(a,b) (((a)<(b)) ? (a) : (b)) - #endif - #ifndef MAX - #define MAX(a,b) (((a)>(b)) ? (a) : (b)) - #endif - /***************************************************************************** * KeyWords definition & action *****************************************************************************/ --- 434,439 ---- *************** *** 4333,4339 **** VARSIZE(value) - VARHDRSZ, 0, FROM_CHAR); scale = Num.post; ! precision = MAX(0, Num.pre) + scale; if (flag) pfree(format); --- 4322,4328 ---- VARSIZE(value) - VARHDRSZ, 0, FROM_CHAR); scale = Num.post; ! precision = Max(0, Num.pre) + scale; if (flag) pfree(format); Index: src/backend/utils/adt/numeric.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v retrieving revision 1.49 diff -c -r1.49 numeric.c *** src/backend/utils/adt/numeric.c 2001/12/11 02:02:12 1.49 --- src/backend/utils/adt/numeric.c 2002/02/18 06:55:45 *************** *** 35,47 **** * Local definitions * ---------- */ - #ifndef MIN - #define MIN(a,b) (((a)<(b)) ? (a) : (b)) - #endif - #ifndef MAX - #define MAX(a,b) (((a)>(b)) ? (a) : (b)) - #endif - #ifndef NAN #define NAN (0.0/0.0) #endif --- 35,40 ---- *************** *** 484,491 **** * Limit the scale value to avoid possible overflow in calculations * below. */ ! scale = MIN(NUMERIC_MAX_RESULT_SCALE, ! MAX(-NUMERIC_MAX_RESULT_SCALE, scale)); /* * Unpack the argument and round it at the proper digit position --- 477,484 ---- * Limit the scale value to avoid possible overflow in calculations * below. */ ! scale = Min(NUMERIC_MAX_RESULT_SCALE, ! Max(-NUMERIC_MAX_RESULT_SCALE, scale)); /* * Unpack the argument and round it at the proper digit position *************** *** 530,536 **** /* * Set result's scale to something reasonable. */ ! scale = MIN(NUMERIC_MAX_DISPLAY_SCALE, MAX(0, scale)); arg.rscale = scale; arg.dscale = scale; --- 523,529 ---- /* * Set result's scale to something reasonable. */ ! scale = Min(NUMERIC_MAX_DISPLAY_SCALE, Max(0, scale)); arg.rscale = scale; arg.dscale = scale; *************** *** 570,577 **** * Limit the scale value to avoid possible overflow in calculations * below. */ ! scale = MIN(NUMERIC_MAX_RESULT_SCALE, ! MAX(-NUMERIC_MAX_RESULT_SCALE, scale)); /* * Unpack the argument and truncate it at the proper digit position --- 563,570 ---- * Limit the scale value to avoid possible overflow in calculations * below. */ ! scale = Min(NUMERIC_MAX_RESULT_SCALE, ! Max(-NUMERIC_MAX_RESULT_SCALE, scale)); /* * Unpack the argument and truncate it at the proper digit position *************** *** 579,590 **** init_var(&arg); set_var_from_num(num, &arg); ! arg.ndigits = MIN(arg.ndigits, MAX(0, arg.weight + scale + 1)); /* * Set result's scale to something reasonable. */ ! scale = MIN(NUMERIC_MAX_DISPLAY_SCALE, MAX(0, scale)); arg.rscale = scale; arg.dscale = scale; --- 572,583 ---- init_var(&arg); set_var_from_num(num, &arg); ! arg.ndigits = Min(arg.ndigits, Max(0, arg.weight + scale + 1)); /* * Set result's scale to something reasonable. */ ! scale = Min(NUMERIC_MAX_DISPLAY_SCALE, Max(0, scale)); arg.rscale = scale; arg.dscale = scale; *************** *** 1214,1224 **** set_var_from_num(num, &arg); ! res_dscale = MAX(arg.dscale, NUMERIC_MIN_DISPLAY_SCALE); ! res_dscale = MIN(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); ! global_rscale = MAX(arg.rscale, NUMERIC_MIN_RESULT_SCALE); ! global_rscale = MAX(global_rscale, res_dscale + 4); ! global_rscale = MIN(global_rscale, NUMERIC_MAX_RESULT_SCALE); sqrt_var(&arg, &result); --- 1207,1217 ---- set_var_from_num(num, &arg); ! res_dscale = Max(arg.dscale, NUMERIC_MIN_DISPLAY_SCALE); ! res_dscale = Min(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); ! global_rscale = Max(arg.rscale, NUMERIC_MIN_RESULT_SCALE); ! global_rscale = Max(global_rscale, res_dscale + 4); ! global_rscale = Min(global_rscale, NUMERIC_MAX_RESULT_SCALE); sqrt_var(&arg, &result); *************** *** 1261,1271 **** init_var(&result); set_var_from_num(num, &arg); ! res_dscale = MAX(arg.dscale, NUMERIC_MIN_DISPLAY_SCALE); ! res_dscale = MIN(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); ! global_rscale = MAX(arg.rscale, NUMERIC_MIN_RESULT_SCALE); ! global_rscale = MAX(global_rscale, res_dscale + 4); ! global_rscale = MIN(global_rscale, NUMERIC_MAX_RESULT_SCALE); exp_var(&arg, &result); --- 1254,1264 ---- init_var(&result); set_var_from_num(num, &arg); ! res_dscale = Max(arg.dscale, NUMERIC_MIN_DISPLAY_SCALE); ! res_dscale = Min(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); ! global_rscale = Max(arg.rscale, NUMERIC_MIN_RESULT_SCALE); ! global_rscale = Max(global_rscale, res_dscale + 4); ! global_rscale = Min(global_rscale, NUMERIC_MAX_RESULT_SCALE); exp_var(&arg, &result); *************** *** 1308,1318 **** init_var(&result); set_var_from_num(num, &arg); ! res_dscale = MAX(arg.dscale, NUMERIC_MIN_DISPLAY_SCALE); ! res_dscale = MIN(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); ! global_rscale = MAX(arg.rscale, NUMERIC_MIN_RESULT_SCALE); ! global_rscale = MAX(global_rscale, res_dscale + 4); ! global_rscale = MIN(global_rscale, NUMERIC_MAX_RESULT_SCALE); ln_var(&arg, &result); --- 1301,1311 ---- init_var(&result); set_var_from_num(num, &arg); ! res_dscale = Max(arg.dscale, NUMERIC_MIN_DISPLAY_SCALE); ! res_dscale = Min(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); ! global_rscale = Max(arg.rscale, NUMERIC_MIN_RESULT_SCALE); ! global_rscale = Max(global_rscale, res_dscale + 4); ! global_rscale = Min(global_rscale, NUMERIC_MAX_RESULT_SCALE); ln_var(&arg, &result); *************** *** 1359,1369 **** set_var_from_num(num1, &arg1); set_var_from_num(num2, &arg2); ! res_dscale = MAX(arg1.dscale + arg2.dscale, NUMERIC_MIN_DISPLAY_SCALE); ! res_dscale = MIN(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); ! global_rscale = MAX(arg1.rscale + arg2.rscale, NUMERIC_MIN_RESULT_SCALE); ! global_rscale = MAX(global_rscale, res_dscale + 4); ! global_rscale = MIN(global_rscale, NUMERIC_MAX_RESULT_SCALE); /* * Call log_var() to compute and return the result --- 1352,1362 ---- set_var_from_num(num1, &arg1); set_var_from_num(num2, &arg2); ! res_dscale = Max(arg1.dscale + arg2.dscale, NUMERIC_MIN_DISPLAY_SCALE); ! res_dscale = Min(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); ! global_rscale = Max(arg1.rscale + arg2.rscale, NUMERIC_MIN_RESULT_SCALE); ! global_rscale = Max(global_rscale, res_dscale + 4); ! global_rscale = Min(global_rscale, NUMERIC_MAX_RESULT_SCALE); /* * Call log_var() to compute and return the result *************** *** 1414,1424 **** set_var_from_num(num1, &arg1); set_var_from_num(num2, &arg2); ! res_dscale = MAX(arg1.dscale + arg2.dscale, NUMERIC_MIN_DISPLAY_SCALE); ! res_dscale = MIN(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); ! global_rscale = MAX(arg1.rscale + arg2.rscale, NUMERIC_MIN_RESULT_SCALE); ! global_rscale = MAX(global_rscale, res_dscale + 4); ! global_rscale = MIN(global_rscale, NUMERIC_MAX_RESULT_SCALE); /* * Call log_var() to compute and return the result --- 1407,1417 ---- set_var_from_num(num1, &arg1); set_var_from_num(num2, &arg2); ! res_dscale = Max(arg1.dscale + arg2.dscale, NUMERIC_MIN_DISPLAY_SCALE); ! res_dscale = Min(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); ! global_rscale = Max(arg1.rscale + arg2.rscale, NUMERIC_MIN_RESULT_SCALE); ! global_rscale = Max(global_rscale, res_dscale + 4); ! global_rscale = Min(global_rscale, NUMERIC_MAX_RESULT_SCALE); /* * Call log_var() to compute and return the result *************** *** 2540,2551 **** } } else ! var->ndigits = MAX(0, MIN(i, var->ndigits)); /* * Allocate space for the result */ ! str = palloc(MAX(0, dscale) + MAX(0, var->weight) + 4); cp = str; /* --- 2533,2544 ---- } } else ! var->ndigits = Max(0, Min(i, var->ndigits)); /* * Allocate space for the result */ ! str = palloc(Max(0, dscale) + Max(0, var->weight) + 4); cp = str; /* *************** *** 2557,2563 **** /* * Output all digits before the decimal point */ ! i = MAX(var->weight, 0); d = 0; while (i >= 0) --- 2550,2556 ---- /* * Output all digits before the decimal point */ ! i = Max(var->weight, 0); d = 0; while (i >= 0) *************** *** 2625,2631 **** return result; } ! n = MAX(0, MIN(var->ndigits, var->weight + var->rscale + 1)); /* truncate leading zeroes */ while (n > 0 && *digit == 0) --- 2618,2624 ---- return result; } ! n = Max(0, Min(var->ndigits, var->weight + var->rscale + 1)); /* truncate leading zeroes */ while (n > 0 && *digit == 0) *************** *** 2717,2723 **** } } else ! var->ndigits = MAX(0, MIN(i, var->ndigits)); /* * Check for overflow - note we can't do this before rounding, because --- 2710,2716 ---- } } else ! var->ndigits = Max(0, Min(i, var->ndigits)); /* * Check for overflow - note we can't do this before rounding, because *************** *** 2825,2832 **** * ---------- */ zero_var(result); ! result->rscale = MAX(var1->rscale, var2->rscale); ! result->dscale = MAX(var1->dscale, var2->dscale); break; case 1: --- 2818,2825 ---- * ---------- */ zero_var(result); ! result->rscale = Max(var1->rscale, var2->rscale); ! result->dscale = Max(var1->dscale, var2->dscale); break; case 1: *************** *** 2869,2876 **** * ---------- */ zero_var(result); ! result->rscale = MAX(var1->rscale, var2->rscale); ! result->dscale = MAX(var1->dscale, var2->dscale); break; case 1: --- 2862,2869 ---- * ---------- */ zero_var(result); ! result->rscale = Max(var1->rscale, var2->rscale); ! result->dscale = Max(var1->dscale, var2->dscale); break; case 1: *************** *** 2949,2956 **** * ---------- */ zero_var(result); ! result->rscale = MAX(var1->rscale, var2->rscale); ! result->dscale = MAX(var1->dscale, var2->dscale); break; case 1: --- 2942,2949 ---- * ---------- */ zero_var(result); ! result->rscale = Max(var1->rscale, var2->rscale); ! result->dscale = Max(var1->dscale, var2->dscale); break; case 1: *************** *** 2993,3000 **** * ---------- */ zero_var(result); ! result->rscale = MAX(var1->rscale, var2->rscale); ! result->dscale = MAX(var1->dscale, var2->dscale); break; case 1: --- 2986,2993 ---- * ---------- */ zero_var(result); ! result->rscale = Max(var1->rscale, var2->rscale); ! result->dscale = Max(var1->dscale, var2->dscale); break; case 1: *************** *** 3344,3351 **** * The minimum and maximum scales are compile time options from * numeric.h): * ! * DR = MIN(MAX(D1 + D2, MIN_DISPLAY_SCALE), MAX_DISPLAY_SCALE) ! * SR = MIN(MAX(MAX(S1 + S2, DR + 4), MIN_RESULT_SCALE), MAX_RESULT_SCALE) * * By default, any result is computed with a minimum of 34 digits * after the decimal point or at least with 4 digits more than --- 3337,3344 ---- * The minimum and maximum scales are compile time options from * numeric.h): * ! * DR = Min(Max(D1 + D2, MIN_DISPLAY_SCALE), MAX_DISPLAY_SCALE) ! * SR = Min(Max(Max(S1 + S2, DR + 4), MIN_RESULT_SCALE), MAX_RESULT_SCALE) * * By default, any result is computed with a minimum of 34 digits * after the decimal point or at least with 4 digits more than *************** *** 3353,3365 **** * ---------- */ res_dscale = var1->dscale + var2->dscale; ! res_dscale = MAX(res_dscale, NUMERIC_MIN_DISPLAY_SCALE); ! res_dscale = MIN(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); res_rscale = var1->rscale + var2->rscale; ! res_rscale = MAX(res_rscale, res_dscale + 4); ! res_rscale = MAX(res_rscale, NUMERIC_MIN_RESULT_SCALE); ! res_rscale = MIN(res_rscale, NUMERIC_MAX_RESULT_SCALE); global_rscale = res_rscale; return res_dscale; --- 3346,3358 ---- * ---------- */ res_dscale = var1->dscale + var2->dscale; ! res_dscale = Max(res_dscale, NUMERIC_MIN_DISPLAY_SCALE); ! res_dscale = Min(res_dscale, NUMERIC_MAX_DISPLAY_SCALE); res_rscale = var1->rscale + var2->rscale; ! res_rscale = Max(res_rscale, res_dscale + 4); ! res_rscale = Max(res_rscale, NUMERIC_MIN_RESULT_SCALE); ! res_rscale = Min(res_rscale, NUMERIC_MAX_RESULT_SCALE); global_rscale = res_rscale; return res_dscale; *************** *** 3398,3404 **** tmp.dscale = div_dscale; /* do trunc() by forgetting digits to the right of the decimal point */ ! tmp.ndigits = MAX(0, MIN(tmp.ndigits, tmp.weight + 1)); global_rscale = var2->rscale + tmp.rscale; --- 3391,3397 ---- tmp.dscale = div_dscale; /* do trunc() by forgetting digits to the right of the decimal point */ ! tmp.ndigits = Max(0, Min(tmp.ndigits, tmp.weight + 1)); global_rscale = var2->rscale + tmp.rscale; *************** *** 3406,3412 **** sub_var(var1, &tmp, result); ! result->dscale = MAX(var1->dscale, var2->dscale); global_rscale = save_global_rscale; free_var(&tmp); --- 3399,3405 ---- sub_var(var1, &tmp, result); ! result->dscale = Max(var1->dscale, var2->dscale); global_rscale = save_global_rscale; free_var(&tmp); *************** *** 3429,3435 **** set_var_from_var(var, &tmp); tmp.rscale = 0; ! tmp.ndigits = MIN(tmp.ndigits, MAX(0, tmp.weight + 1)); if (tmp.sign == NUMERIC_POS && cmp_var(var, &tmp) != 0) add_var(&tmp, &const_one, &tmp); --- 3422,3428 ---- set_var_from_var(var, &tmp); tmp.rscale = 0; ! tmp.ndigits = Min(tmp.ndigits, Max(0, tmp.weight + 1)); if (tmp.sign == NUMERIC_POS && cmp_var(var, &tmp) != 0) add_var(&tmp, &const_one, &tmp); *************** *** 3454,3460 **** set_var_from_var(var, &tmp); tmp.rscale = 0; ! tmp.ndigits = MIN(tmp.ndigits, MAX(0, tmp.weight + 1)); if (tmp.sign == NUMERIC_NEG && cmp_var(var, &tmp) != 0) sub_var(&tmp, &const_one, &tmp); --- 3447,3453 ---- set_var_from_var(var, &tmp); tmp.rscale = 0; ! tmp.ndigits = Min(tmp.ndigits, Max(0, tmp.weight + 1)); if (tmp.sign == NUMERIC_NEG && cmp_var(var, &tmp) != 0) sub_var(&tmp, &const_one, &tmp); *************** *** 3860,3868 **** NumericDigit *var1digits = var1->digits; NumericDigit *var2digits = var2->digits; ! res_weight = MAX(var1->weight, var2->weight) + 1; ! res_rscale = MAX(var1->rscale, var2->rscale); ! res_dscale = MAX(var1->dscale, var2->dscale); res_ndigits = res_rscale + res_weight + 1; if (res_ndigits <= 0) res_ndigits = 1; --- 3853,3861 ---- NumericDigit *var1digits = var1->digits; NumericDigit *var2digits = var2->digits; ! res_weight = Max(var1->weight, var2->weight) + 1; ! res_rscale = Max(var1->rscale, var2->rscale); ! res_dscale = Max(var1->dscale, var2->dscale); res_ndigits = res_rscale + res_weight + 1; if (res_ndigits <= 0) res_ndigits = 1; *************** *** 3948,3955 **** NumericDigit *var2digits = var2->digits; res_weight = var1->weight; ! res_rscale = MAX(var1->rscale, var2->rscale); ! res_dscale = MAX(var1->dscale, var2->dscale); res_ndigits = res_rscale + res_weight + 1; if (res_ndigits <= 0) res_ndigits = 1; --- 3941,3948 ---- NumericDigit *var2digits = var2->digits; res_weight = var1->weight; ! res_rscale = Max(var1->rscale, var2->rscale); ! res_dscale = Max(var1->dscale, var2->dscale); res_ndigits = res_rscale + res_weight + 1; if (res_ndigits <= 0) res_ndigits = 1;