summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrigori Goronzy <greg@blackbox>2009-07-08 00:25:05 +0200
committerGrigori Goronzy <greg@blackbox>2009-07-08 00:25:05 +0200
commit55e9f91ec4868e8cd9098b367a0d935d703290d4 (patch)
tree6b2b2526ce4b27929f2f9a2345abb040f9249915
parent6302f307524b430992bd7d71036f7b46c702f678 (diff)
downloadlibass-55e9f91ec4868e8cd9098b367a0d935d703290d4.tar.bz2
libass-55e9f91ec4868e8cd9098b367a0d935d703290d4.tar.xz
Correctly round doubles to integers
mystrtoi and mystrtoll did not round correctly for negative numbers, this was fixed.
-rw-r--r--libass/ass_utils.c4
1 files 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