summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-numeric-ext/src/numeric_ext.c
diff options
context:
space:
mode:
authorHiroshi Mimaki <[email protected]>2019-10-18 14:46:03 +0900
committerHiroshi Mimaki <[email protected]>2019-10-18 14:46:03 +0900
commitb6546835457d1935a9c77965686b2a1256874d96 (patch)
tree724cfd71a7c956b0648e8c58f3717d797fff5f29 /mrbgems/mruby-numeric-ext/src/numeric_ext.c
parent8ee516436b8d174a50764939bee23a442aa00b3f (diff)
parent20d01f118ddb7e7f2f36926a7a3db35573611857 (diff)
downloadmruby-b6546835457d1935a9c77965686b2a1256874d96.tar.gz
mruby-b6546835457d1935a9c77965686b2a1256874d96.zip
Merge master.
Diffstat (limited to 'mrbgems/mruby-numeric-ext/src/numeric_ext.c')
-rw-r--r--mrbgems/mruby-numeric-ext/src/numeric_ext.c54
1 files changed, 17 insertions, 37 deletions
diff --git a/mrbgems/mruby-numeric-ext/src/numeric_ext.c b/mrbgems/mruby-numeric-ext/src/numeric_ext.c
index cd8bbf187..f8aff54bc 100644
--- a/mrbgems/mruby-numeric-ext/src/numeric_ext.c
+++ b/mrbgems/mruby-numeric-ext/src/numeric_ext.c
@@ -1,38 +1,6 @@
#include <limits.h>
#include <mruby.h>
-
-static inline mrb_int
-to_int(mrb_state *mrb, mrb_value x)
-{
- x = mrb_to_int(mrb, x);
- return mrb_fixnum(x);
-}
-
-/*
- * Document-method: Integer#chr
- * call-seq:
- * int.chr -> string
- *
- * Returns a string containing the character represented by the +int+'s value
- * according to +encoding+.
- *
- * 65.chr #=> "A"
- * 230.chr #=> "\xE6"
- */
-static mrb_value
-mrb_int_chr(mrb_state *mrb, mrb_value x)
-{
- mrb_int chr;
- char c;
-
- chr = to_int(mrb, x);
- if (chr >= (1 << CHAR_BIT)) {
- mrb_raisef(mrb, E_RANGE_ERROR, "%S out of char range", x);
- }
- c = (char)chr;
-
- return mrb_str_new(mrb, &c, 1);
-}
+#include <mruby/numeric.h>
/*
* call-seq:
@@ -46,7 +14,7 @@ mrb_int_allbits(mrb_state *mrb, mrb_value self)
mrb_int n, m;
mrb_get_args(mrb, "i", &m);
- n = to_int(mrb, self);
+ n = mrb_int(mrb, self);
return mrb_bool_value((n & m) == m);
}
@@ -62,7 +30,7 @@ mrb_int_anybits(mrb_state *mrb, mrb_value self)
mrb_int n, m;
mrb_get_args(mrb, "i", &m);
- n = to_int(mrb, self);
+ n = mrb_int(mrb, self);
return mrb_bool_value((n & m) != 0);
}
@@ -78,7 +46,7 @@ mrb_int_nobits(mrb_state *mrb, mrb_value self)
mrb_int n, m;
mrb_get_args(mrb, "i", &m);
- n = to_int(mrb, self);
+ n = mrb_int(mrb, self);
return mrb_bool_value((n & m) == 0);
}
@@ -87,10 +55,22 @@ mrb_mruby_numeric_ext_gem_init(mrb_state* mrb)
{
struct RClass *i = mrb_module_get(mrb, "Integral");
- mrb_define_method(mrb, i, "chr", mrb_int_chr, MRB_ARGS_NONE());
mrb_define_method(mrb, i, "allbits?", mrb_int_allbits, MRB_ARGS_REQ(1));
mrb_define_method(mrb, i, "anybits?", mrb_int_anybits, MRB_ARGS_REQ(1));
mrb_define_method(mrb, i, "nobits?", mrb_int_nobits, MRB_ARGS_REQ(1));
+
+#ifndef MRB_WITHOUT_FLOAT
+ mrb_define_const(mrb, mrb->float_class, "RADIX", mrb_fixnum_value(MRB_FLT_RADIX));
+ mrb_define_const(mrb, mrb->float_class, "MANT_DIG", mrb_fixnum_value(MRB_FLT_MANT_DIG));
+ mrb_define_const(mrb, mrb->float_class, "EPSILON", mrb_float_value(mrb, MRB_FLT_EPSILON));
+ mrb_define_const(mrb, mrb->float_class, "DIG", mrb_fixnum_value(MRB_FLT_DIG));
+ mrb_define_const(mrb, mrb->float_class, "MIN_EXP", mrb_fixnum_value(MRB_FLT_MIN_EXP));
+ mrb_define_const(mrb, mrb->float_class, "MIN", mrb_float_value(mrb, MRB_FLT_MIN));
+ mrb_define_const(mrb, mrb->float_class, "MIN_10_EXP", mrb_fixnum_value(MRB_FLT_MIN_10_EXP));
+ mrb_define_const(mrb, mrb->float_class, "MAX_EXP", mrb_fixnum_value(MRB_FLT_MAX_EXP));
+ mrb_define_const(mrb, mrb->float_class, "MAX", mrb_float_value(mrb, MRB_FLT_MAX));
+ mrb_define_const(mrb, mrb->float_class, "MAX_10_EXP", mrb_fixnum_value(MRB_FLT_MAX_10_EXP));
+#endif /* MRB_WITHOUT_FLOAT */
}
void