From 028c67766b0bcbd453dbdeab609267bdce56b290 Mon Sep 17 00:00:00 2001 From: Alasdair Armstrong Date: Wed, 27 Jun 2018 19:40:54 +0100 Subject: Actually fix real literals, and add a test for various properties --- lib/sail.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/sail.c b/lib/sail.c index 323ea7d8..e0daf0cf 100644 --- a/lib/sail.c +++ b/lib/sail.c @@ -969,10 +969,13 @@ void real_power(real *rop, const real base, const sail_int exp) void CREATE_OF(real, sail_string)(real *rop, const sail_string op) { + int decimal; + int total; + mpq_init(*rop); - gmp_sscanf(op, "%Zd.%Zd", sail_lib_tmp1, sail_lib_tmp2); + gmp_sscanf(op, "%Zd.%n%Zd%n", sail_lib_tmp1, &decimal, sail_lib_tmp2, &total); - unsigned long len = (unsigned long) mpz_sizeinbase(sail_lib_tmp2, 10); + int len = total - decimal; mpz_ui_pow_ui(sail_lib_tmp3, 10, len); mpz_set(mpq_numref(*rop), sail_lib_tmp2); mpz_set(mpq_denref(*rop), sail_lib_tmp3); -- cgit v1.2.3