From 2d5b15ea68bf4b09afd2374660c22171f8ca3e52 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 27 Mar 2022 18:36:14 -0400 Subject: opt: Use floats consistently for probabilities and costs --- opt.c | 6 +++--- parse.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/opt.c b/opt.c index e21a7ad..f8c0ba3 100644 --- a/opt.c +++ b/opt.c @@ -953,7 +953,7 @@ done: } /** Swap the children of a binary expression if it would reduce the cost. */ -static bool reorder_expr(const struct opt_state *state, struct bfs_expr *expr, double swapped_cost) { +static bool reorder_expr(const struct opt_state *state, struct bfs_expr *expr, float swapped_cost) { if (swapped_cost < expr->cost) { bool debug = opt_debug(state, 3, "cost: %pe <==> ", expr); struct bfs_expr *lhs = expr->lhs; @@ -995,8 +995,8 @@ static bool reorder_expr_recursive(const struct opt_state *state, struct bfs_exp if (expr->eval_fn == eval_and || expr->eval_fn == eval_or) { if (lhs->pure && rhs->pure) { - double rhs_prob = expr->eval_fn == eval_and ? rhs->probability : 1.0 - rhs->probability; - double swapped_cost = rhs->cost + rhs_prob*lhs->cost; + float rhs_prob = expr->eval_fn == eval_and ? rhs->probability : 1.0 - rhs->probability; + float swapped_cost = rhs->cost + rhs_prob*lhs->cost; ret |= reorder_expr(state, expr, swapped_cost); } } diff --git a/parse.c b/parse.c index 6dc8f5f..ecf1387 100644 --- a/parse.c +++ b/parse.c @@ -2672,12 +2672,12 @@ static struct bfs_expr *parse_type(struct parser_state *state, int x, int arg2) } unsigned int types = 0; - double probability = 0.0; + float probability = 0.0; const char *c = expr->argv[1]; while (true) { enum bfs_type type; - double type_prob; + float type_prob; switch (*c) { case 'b': -- cgit v1.2.3