diff options
| author | Lukas Joeressen <[email protected]> | 2015-06-15 15:03:44 +0200 |
|---|---|---|
| committer | Lukas Joeressen <[email protected]> | 2015-06-15 15:03:44 +0200 |
| commit | 95fa22a65cf0866afaf3efd933a180509922f047 (patch) | |
| tree | 72f50a9690142f7edf03e236457cea25fbb38108 /mrbgems/mruby-time/src | |
| parent | 97a18ff4d9db48a72b3e63f2d6fd7c7958e98c97 (diff) | |
| download | mruby-95fa22a65cf0866afaf3efd933a180509922f047.tar.gz mruby-95fa22a65cf0866afaf3efd933a180509922f047.zip | |
Rounding errors could make time_alloc imprecise
Diffstat (limited to 'mrbgems/mruby-time/src')
| -rw-r--r-- | mrbgems/mruby-time/src/time.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index b377f3e33..36bbbe00a 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -6,6 +6,7 @@ #include <stdio.h> #include <time.h> +#include <math.h> #include "mruby.h" #include "mruby/class.h" #include "mruby/data.h" @@ -208,12 +209,12 @@ time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone) out_of_range: mrb_raisef(mrb, E_ARGUMENT_ERROR, "%S out of Time range", mrb_float_value(mrb, sec)); } - tm->usec = (time_t)((sec - tm->sec) * 1.0e6 + usec); + tm->usec = (time_t)llrint((sec - tm->sec) * 1.0e6 + usec); while (tm->usec < 0) { tm->sec--; tm->usec += 1000000; } - while (tm->usec > 1000000) { + while (tm->usec >= 1000000) { tm->sec++; tm->usec -= 1000000; } |
