Permalink
Browse files

add round if not defined

  • Loading branch information...
1 parent ef6c8cd commit 37b1d6484e5ea893bc510d1f929c2056c471e70e @takeru committed Apr 29, 2012
Showing with 16 additions and 0 deletions.
  1. +16 −0 src/numeric.c
View
@@ -109,6 +109,22 @@ const unsigned char mrb_nan[] = "\x7f\xc0\x00\x00";
#define fmod(x,y) fmodf(x,y)
#endif
+#ifndef round
+mrb_float 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;
+}
+#endif
+
void mrb_cmperr(mrb_state *mrb, mrb_value x, mrb_value y);
void

0 comments on commit 37b1d64

Please sign in to comment.