From 9c5fab4f4c3ef7cd39eececf6984378e4a48b56e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 19 Mar 2014 00:19:16 -0700 Subject: * arith.c (int_flo): Fix non-handling of negative values. --- ChangeLog | 4 ++++ arith.c | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f65b56df..f3eaa15a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-03-19 Kaz Kylheku + + * arith.c (int_flo): Fix non-handling of negative values. + 2014-03-19 Kaz Kylheku * arith.c (tofloat, toint): New functions. diff --git a/arith.c b/arith.c index 63391848..d207579a 100644 --- a/arith.c +++ b/arith.c @@ -1474,7 +1474,7 @@ val int_flo(val f) sprintf(text, "%.64g", d); - if (!isdigit(text[0])) + if (!isdigit(text[0]) && (text[0] != '-' || !isdigit(text[1]))) uw_throwf(error_s, lit("int-flo: cannot convert # to integer"), nao); @@ -1483,11 +1483,11 @@ val int_flo(val f) have_point = (strchr(text, '.') != 0); if (have_exp && have_point) - sscanf(text, "%127[0-9].%127[0-9]e%d", mint, mfrac, &exp); + sscanf(text, "%127[-0-9].%127[0-9]e%d", mint, mfrac, &exp); else if (have_exp) - sscanf(text, "%127[0-9]e%d", mint, &exp); + sscanf(text, "%127[-0-9]e%d", mint, &exp); else if (have_point) - sscanf(text, "%127[0-9].%127[0-9]", mint, mfrac); + sscanf(text, "%127[-0-9].%127[0-9]", mint, mfrac); else return int_str(string_utf8(text), nil); -- cgit v1.2.3