summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-07-27 15:05:16 +0900
committerGitHub <[email protected]>2019-07-27 15:05:16 +0900
commit2f0a95768b8753448eb819e1bd3d250b69844828 (patch)
tree11350713c326d2343a3054c74f317549248502d7
parentb58f769c96462fb8b3b2453ba2aae8c83932f84b (diff)
parent1467c14adcd45ce6acaa684b377cf66323b0c312 (diff)
downloadmruby-2f0a95768b8753448eb819e1bd3d250b69844828.tar.gz
mruby-2f0a95768b8753448eb819e1bd3d250b69844828.zip
Merge pull request #4598 from dearblue/time-without-float
Fix mruby-time with `MRB_WITHOUT_FLOAT`; ref d74355061
-rw-r--r--mrbgems/mruby-time/src/time.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c
index 3c0ab6ca0..b8b4c5a0d 100644
--- a/mrbgems/mruby-time/src/time.c
+++ b/mrbgems/mruby-time/src/time.c
@@ -4,7 +4,10 @@
** See Copyright Notice in mruby.h
*/
+#ifndef MRB_WITHOUT_FLOAT
#include <math.h>
+#endif
+
#include <time.h>
#include <mruby.h>
#include <mruby/class.h>
@@ -26,8 +29,10 @@ double round(double x) {
}
#endif
-#if !defined(__MINGW64__) && defined(_WIN32)
-# define llround(x) round(x)
+#ifdef MRB_WITHOUT_FLOAT
+# if !defined(__MINGW64__) && defined(_WIN32)
+# define llround(x) round(x)
+# endif
#endif
#if defined(__MINGW64__) || defined(__MINGW32__)
@@ -276,7 +281,11 @@ time_alloc(mrb_state *mrb, mrb_sec sec, mrb_int usec, enum mrb_timezone timezone
}
tm = (struct mrb_time *)mrb_malloc(mrb, sizeof(struct mrb_time));
tm->sec = tsec;
+#ifdef MRB_WITHOUT_FLOAT
+ tm->usec = (time_t)usec;
+#else
tm->usec = (time_t)llround((sec - tm->sec) * 1.0e6 + usec);
+#endif
if (tm->usec < 0) {
long sec2 = (long)NDIV(tm->usec,1000000); /* negative div */
tm->usec -= sec2 * 1000000;