From 55e9f91ec4868e8cd9098b367a0d935d703290d4 Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Wed, 8 Jul 2009 00:25:05 +0200 Subject: Correctly round doubles to integers mystrtoi and mystrtoll did not round correctly for negative numbers, this was fixed. --- libass/ass_utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libass/ass_utils.c b/libass/ass_utils.c index 16f868a..5f63268 100644 --- a/libass/ass_utils.c +++ b/libass/ass_utils.c @@ -33,7 +33,7 @@ int mystrtoi(char **p, int *res) double temp_res; char *start = *p; temp_res = strtod(*p, p); - *res = (int) (temp_res + 0.5); + *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5)); if (*p != start) return 1; else @@ -45,7 +45,7 @@ int mystrtoll(char **p, long long *res) double temp_res; char *start = *p; temp_res = strtod(*p, p); - *res = (long long) (temp_res + 0.5); + *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5)); if (*p != start) return 1; else -- cgit v1.2.3