From ec6624dfc767e9a65abe143a04c3fe6f58d0f4fe Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 1 Nov 2013 22:05:49 -0500 Subject: [PATCH] Prioritize single->double conversions for FindBestProto() - The binary form of ZCC_OpInfoType::FindBestProto() needs special handling for conversion from single to double precision floating point so that it doesn't choose an integer form over a floating point form when picking the best prototype. --- src/zscript/zcc_expr.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/zscript/zcc_expr.cpp b/src/zscript/zcc_expr.cpp index dc7a08d1c..32d0c9374 100644 --- a/src/zscript/zcc_expr.cpp +++ b/src/zscript/zcc_expr.cpp @@ -10,6 +10,8 @@ #define luai_nummod(a,b) ((a) - floor((a)/(b))*(b)) +static void FtoD(ZCC_ExprConstant *expr, FSharedStringArena &str_arena); + ZCC_OpInfoType ZCC_OpInfo[PEX_COUNT_OF] = { #define xx(a,z) { #a, NULL }, @@ -134,7 +136,19 @@ ZCC_OpProto *ZCC_OpInfoType::FindBestProto( { // one or both operator types are unreachable continue; } - int dist = MIN(dist1, dist2); + // Do not count F32->F64 conversions in the distance comparisons. If we do, then + // [[float32 (op) int]] will choose the integer version instead of the floating point + // version, which we do not want. + int test_dist1 = dist1, test_dist2 = dist2; + if (routes[0][cur_route1][0]->ConvertConstant == FtoD) + { + test_dist1--; + } + if (routes[1][cur_route2][0]->ConvertConstant == FtoD) + { + test_dist2--; + } + int dist = MIN(test_dist1, test_dist2); if (dist < best_low_dist) { best_low_dist = dist;