1515 *
1616 *
1717 * IDENTIFICATION
18- * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.98 2001/10/03 18:25:59 tgl Exp $
18+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.99 2001/10/13 23:32:33 tgl Exp $
1919 *
2020 *-------------------------------------------------------------------------
2121 */
@@ -581,7 +581,18 @@ scalarineqsel(Query *root, Oid operator, bool isgt,
581581 else if (val >= high )
582582 binfrac = 1.0 ;
583583 else
584+ {
584585 binfrac = (val - low ) / (high - low );
586+ /*
587+ * Watch out for the possibility that we got a NaN
588+ * or Infinity from the division. This can happen
589+ * despite the previous checks, if for example
590+ * "low" is -Infinity.
591+ */
592+ if (isnan (binfrac ) ||
593+ binfrac < 0.0 || binfrac > 1.0 )
594+ binfrac = 0.5 ;
595+ }
585596 }
586597 else
587598 {
@@ -1665,8 +1676,8 @@ icnlikejoinsel(PG_FUNCTION_ARGS)
16651676 * subroutines in pg_type.
16661677 *
16671678 * All numeric datatypes are simply converted to their equivalent
1668- * "double" values. XXX what about NUMERIC values that are outside
1669- * the range of "double"?
1679+ * "double" values. ( NUMERIC values that are outside the range of "double"
1680+ * are clamped to +/- HUGE_VAL.)
16701681 *
16711682 * String datatypes are converted by convert_string_to_scalar(),
16721683 * which is explained below. The reason why this routine deals with
@@ -1677,8 +1688,9 @@ icnlikejoinsel(PG_FUNCTION_ARGS)
16771688 *
16781689 * The several datatypes representing absolute times are all converted
16791690 * to Timestamp, which is actually a double, and then we just use that
1680- * double value. Note this will give bad results for the various "special"
1681- * values of Timestamp --- what can we do with those?
1691+ * double value. Note this will give correct results even for the "special"
1692+ * values of Timestamp, since those are chosen to compare correctly;
1693+ * see timestamp_cmp.
16821694 *
16831695 * The several datatypes representing relative times (intervals) are all
16841696 * converted to measurements expressed in seconds.
@@ -1793,8 +1805,10 @@ convert_numeric_to_scalar(Datum value, Oid typid)
17931805 case FLOAT8OID :
17941806 return (double ) DatumGetFloat8 (value );
17951807 case NUMERICOID :
1796- return (double ) DatumGetFloat8 (DirectFunctionCall1 (numeric_float8 ,
1797- value ));
1808+ /* Note: out-of-range values will be clamped to +-HUGE_VAL */
1809+ return (double )
1810+ DatumGetFloat8 (DirectFunctionCall1 (numeric_float8_no_overflow ,
1811+ value ));
17981812 case OIDOID :
17991813 case REGPROCOID :
18001814 /* we can treat OIDs as integers... */
0 commit comments