@ -17,6 +17,8 @@
*/
*/
# include "postgres.h"
# include "postgres.h"
# include <math.h>
# include "access/htup_details.h"
# include "access/htup_details.h"
# include "catalog/pg_operator.h"
# include "catalog/pg_operator.h"
# include "catalog/pg_statistic.h"
# include "catalog/pg_statistic.h"
@ -750,19 +752,19 @@ get_position(TypeCacheEntry *typcache, RangeBound *value, RangeBound *hist1,
static double
static double
get_len_position ( double value , double hist1 , double hist2 )
get_len_position ( double value , double hist1 , double hist2 )
{
{
if ( ! is_ infinite ( hist1 ) & & ! is_ infinite ( hist2 ) )
if ( ! isinf ( hist1 ) & & ! isinf ( hist2 ) )
{
{
/*
/*
* Both bounds are finite . The value should be finite too , because it
* Both bounds are finite . The value should be finite too , because it
* lies somewhere between the bounds . If it doesn ' t , just return
* lies somewhere between the bounds . If it doesn ' t , just return
* something .
* something .
*/
*/
if ( is_ infinite ( value ) )
if ( isinf ( value ) )
return 0.5 ;
return 0.5 ;
return 1.0 - ( hist2 - value ) / ( hist2 - hist1 ) ;
return 1.0 - ( hist2 - value ) / ( hist2 - hist1 ) ;
}
}
else if ( is_ infinite ( hist1 ) & & ! is_ infinite ( hist2 ) )
else if ( isinf ( hist1 ) & & ! isinf ( hist2 ) )
{
{
/*
/*
* Lower bin boundary is - infinite , upper is finite . Return 1.0 to
* Lower bin boundary is - infinite , upper is finite . Return 1.0 to
@ -770,7 +772,7 @@ get_len_position(double value, double hist1, double hist2)
*/
*/
return 1.0 ;
return 1.0 ;
}
}
else if ( is_ infinite ( hist1 ) & & is_ infinite ( hist2 ) )
else if ( isinf ( hist1 ) & & isinf ( hist2 ) )
{
{
/* same as above, but in reverse */
/* same as above, but in reverse */
return 0.0 ;
return 0.0 ;
@ -851,7 +853,7 @@ calc_length_hist_frac(Datum *length_hist_values, int length_hist_nvalues,
return 0.0 ; /* shouldn't happen, but doesn't hurt to check */
return 0.0 ; /* shouldn't happen, but doesn't hurt to check */
/* All lengths in the table are <= infinite. */
/* All lengths in the table are <= infinite. */
if ( is_ infinite ( length2 ) & & equal )
if ( isinf ( length2 ) & & equal )
return 1.0 ;
return 1.0 ;
/*----------
/*----------
@ -978,7 +980,7 @@ calc_length_hist_frac(Datum *length_hist_values, int length_hist_nvalues,
* length2 is infinite . It ' s not clear what the correct value would be in
* length2 is infinite . It ' s not clear what the correct value would be in
* that case , so 0.5 seems as good as any value .
* that case , so 0.5 seems as good as any value .
*/
*/
if ( is_ infinite ( area ) & & is_ infinite ( length2 ) )
if ( isinf ( area ) & & isinf ( length2 ) )
frac = 0.5 ;
frac = 0.5 ;
else
else
frac = area / ( length2 - length1 ) ;
frac = area / ( length2 - length1 ) ;