summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-05-01 23:05:27 +0900
committerYukihiro Matsumoto <[email protected]>2012-05-01 23:05:27 +0900
commitde67c321fec654c58be06c6b1b79084db286f9f9 (patch)
tree5ce949e9cba44c76adc8f123cb2159af83b15999 /src
parent4fd260489e63021a46370656cf2f61573e553a17 (diff)
downloadmruby-de67c321fec654c58be06c6b1b79084db286f9f9.tar.gz
mruby-de67c321fec654c58be06c6b1b79084db286f9f9.zip
remove round(3) to avoid -std=c99
Diffstat (limited to 'src')
-rw-r--r--src/numeric.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/numeric.c b/src/numeric.c
index bf255f973..d5475bc8e 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -102,13 +102,30 @@ const unsigned char mrb_nan[] = "\x7f\xc0\x00\x00";
#endif
#ifdef MRB_USE_FLOAT
-#define round(f) roundf(f)
#define floor(f) floorf(f)
#define ceil(f) ceilf(f)
#define floor(f) floorf(f)
#define fmod(x,y) fmodf(x,y)
#endif
+static mrb_float
+mrb_round(mrb_float x)
+{
+ mrb_float f;
+
+ if (x > 0.0) {
+ f = floor(x);
+ x = f + (x - f >= 0.5);
+ }
+ else if (x < 0.0) {
+ f = ceil(x);
+ x = f - (f - x >= 0.5);
+ }
+ return x;
+}
+
+#define round(x) mrb_round(x)
+
void mrb_cmperr(mrb_state *mrb, mrb_value x, mrb_value y);
void