15
15
*
16
16
*
17
17
* 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 $
19
19
*
20
20
*-------------------------------------------------------------------------
21
21
*/
@@ -581,7 +581,18 @@ scalarineqsel(Query *root, Oid operator, bool isgt,
581
581
else if (val >= high )
582
582
binfrac = 1.0 ;
583
583
else
584
+ {
584
585
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
+ }
585
596
}
586
597
else
587
598
{
@@ -1665,8 +1676,8 @@ icnlikejoinsel(PG_FUNCTION_ARGS)
1665
1676
* subroutines in pg_type.
1666
1677
*
1667
1678
* 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.)
1670
1681
*
1671
1682
* String datatypes are converted by convert_string_to_scalar(),
1672
1683
* which is explained below. The reason why this routine deals with
@@ -1677,8 +1688,9 @@ icnlikejoinsel(PG_FUNCTION_ARGS)
1677
1688
*
1678
1689
* The several datatypes representing absolute times are all converted
1679
1690
* 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.
1682
1694
*
1683
1695
* The several datatypes representing relative times (intervals) are all
1684
1696
* converted to measurements expressed in seconds.
@@ -1793,8 +1805,10 @@ convert_numeric_to_scalar(Datum value, Oid typid)
1793
1805
case FLOAT8OID :
1794
1806
return (double ) DatumGetFloat8 (value );
1795
1807
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 ));
1798
1812
case OIDOID :
1799
1813
case REGPROCOID :
1800
1814
/* we can treat OIDs as integers... */
0 commit comments