From a1a2d6b75e800216bdb10f474e3794e5c1b23f6e Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Wed, 22 Dec 2010 18:31:33 +0100 Subject: [PATCH] Use correct format when scanning double floating point values. --- Makefile | 4 +++- distributed/distributed.c | 2 +- gtp.c | 2 +- util.h | 8 ++++++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 8140a14..2f9c166 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,10 @@ else LDFLAGS=-lm -pthread -lrt -ldl -rdynamic endif +# Use make DOUBLE=1 in large configurations with counts > 1M +# where 24 bits of floating_t mantissa become insufficient. ifdef DOUBLE - CUSTOM_CFLAGS+=-Dfloating_t=double + CUSTOM_CFLAGS+=-DDOUBLE endif # Profiling: diff --git a/distributed/distributed.c b/distributed/distributed.c index 0bc9887..50ed721 100644 --- a/distributed/distributed.c +++ b/distributed/distributed.c @@ -224,7 +224,7 @@ select_best_move(struct board *b, struct move_stats *stats, int *played, char move[64]; struct move_stats s; - while (r && sscanf(++r, "%63s %d %f", move, &s.playouts, &s.value) == 3) { + while (r && sscanf(++r, "%63s %d " PRIfloating, move, &s.playouts, &s.value) == 3) { coord_t c = str2scoord(move, board_size(b)); assert (c >= resign && c < board_size2(b) && s.playouts >= 0); diff --git a/gtp.c b/gtp.c index f7fc24f..2668624 100644 --- a/gtp.c +++ b/gtp.c @@ -211,7 +211,7 @@ gtp_parse(struct board *board, struct engine *engine, struct time_info *ti, char } else if (!strcasecmp(cmd, "komi")) { char *arg; next_tok(arg); - sscanf(arg, "%f", &board->komi); + sscanf(arg, PRIfloating, &board->komi); if (DEBUGL(1)) board_print(board, stderr); diff --git a/util.h b/util.h index 7e531df..895ff36 100644 --- a/util.h +++ b/util.h @@ -5,10 +5,14 @@ /* Misc. definitions. */ -/* Use make -Dfloating_t=double in large configurations with counts > 1M, +/* Use make DOUBLE=1 in large configurations with counts > 1M * where 24 bits of floating_t mantissa become insufficient. */ -#ifndef floating_t +#ifdef DOUBLE +# define floating_t double +# define PRIfloating "%lf" +#else # define floating_t float +# define PRIfloating "%f" #endif #define likely(x) __builtin_expect(!!(x), 1) -- 2.11.4.GIT