diff --git a/src/hnsw.c b/src/hnsw.c
index 0850a69e7..97e43a8a7 100644
--- a/src/hnsw.c
+++ b/src/hnsw.c
@@ -9,6 +9,7 @@
 #include "commands/vacuum.h"
 #include "hnsw.h"
 #include "miscadmin.h"
+#include "utils/float.h"
 #include "utils/guc.h"
 #include "utils/selfuncs.h"
 
@@ -112,8 +113,8 @@ hnswcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
 	/* Never use index without order */
 	if (path->indexorderbys == NULL)
 	{
-		*indexStartupCost = DBL_MAX;
-		*indexTotalCost = DBL_MAX;
+		*indexStartupCost = get_float8_infinity();
+		*indexTotalCost = get_float8_infinity();
 		*indexSelectivity = 0;
 		*indexCorrelation = 0;
 		*indexPages = 0;
diff --git a/src/ivfflat.c b/src/ivfflat.c
index 415579b7a..a1e2e1d28 100644
--- a/src/ivfflat.c
+++ b/src/ivfflat.c
@@ -7,6 +7,7 @@
 #include "commands/progress.h"
 #include "commands/vacuum.h"
 #include "ivfflat.h"
+#include "utils/float.h"
 #include "utils/guc.h"
 #include "utils/selfuncs.h"
 #include "utils/spccache.h"
@@ -78,8 +79,8 @@ ivfflatcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
 	/* Never use index without order */
 	if (path->indexorderbys == NULL)
 	{
-		*indexStartupCost = DBL_MAX;
-		*indexTotalCost = DBL_MAX;
+		*indexStartupCost = get_float8_infinity();
+		*indexTotalCost = get_float8_infinity();
 		*indexSelectivity = 0;
 		*indexCorrelation = 0;
 		*indexPages = 0;
