summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-complex
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-10-15 18:31:06 +0900
committerGitHub <[email protected]>2020-10-15 18:31:06 +0900
commit9cebddf9fe83ae0acde6f64f291fa3c9fc22880f (patch)
tree6f9ca4f2941c3da48a504c937719adca36e4cdfe /mrbgems/mruby-complex
parent8c276f95be2f4e9deed73f08125a23a6746cb517 (diff)
parent21e07d61138a87891dc780efaa28e6c76a39378f (diff)
downloadmruby-9cebddf9fe83ae0acde6f64f291fa3c9fc22880f.tar.gz
mruby-9cebddf9fe83ae0acde6f64f291fa3c9fc22880f.zip
Merge pull request #5084 from mruby/mruby3
Mruby3
Diffstat (limited to 'mrbgems/mruby-complex')
-rw-r--r--mrbgems/mruby-complex/mrblib/complex.rb2
-rw-r--r--mrbgems/mruby-complex/src/complex.c14
-rw-r--r--mrbgems/mruby-complex/test/complex.rb8
3 files changed, 12 insertions, 12 deletions
diff --git a/mrbgems/mruby-complex/mrblib/complex.rb b/mrbgems/mruby-complex/mrblib/complex.rb
index 74c128a07..67f940865 100644
--- a/mrbgems/mruby-complex/mrblib/complex.rb
+++ b/mrbgems/mruby-complex/mrblib/complex.rb
@@ -104,7 +104,7 @@ class Complex < Numeric
alias_method :imag, :imaginary
- [Fixnum, Float].each do |cls|
+ [Integer, Float].each do |cls|
[:+, :-, :*, :/, :==].each do |op|
cls.instance_eval do
original_operator_name = :"__original_operator_#{op}_complex"
diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c
index 0432da633..6b7486ab0 100644
--- a/mrbgems/mruby-complex/src/complex.c
+++ b/mrbgems/mruby-complex/src/complex.c
@@ -3,8 +3,8 @@
#include <mruby/numeric.h>
#include <math.h>
-#ifdef MRB_WITHOUT_FLOAT
-# error Complex conflicts 'MRB_WITHOUT_FLOAT' configuration in your 'build_config.rb'
+#ifdef MRB_NO_FLOAT
+# error Complex conflicts with 'MRB_NO_FLOAT' configuration
#endif
struct mrb_complex {
@@ -12,13 +12,13 @@ struct mrb_complex {
mrb_float imaginary;
};
-#ifdef MRB_USE_FLOAT
+#ifdef MRB_USE_FLOAT32
#define F(x) x##f
#else
#define F(x) x
#endif
-#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT)
+#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT32)
#define COMPLEX_USE_ISTRUCT
/* use TT_ISTRUCT */
@@ -69,7 +69,7 @@ complex_ptr(mrb_state *mrb, mrb_value v)
static mrb_value
complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
{
- struct RClass *c = mrb_class_get(mrb, "Complex");
+ struct RClass *c = mrb_class_get_id(mrb, MRB_SYM(Complex));
struct mrb_complex *p;
struct RBasic *comp = complex_alloc(mrb, c, &p);
p->real = real;
@@ -122,7 +122,7 @@ complex_to_i(mrb_state *mrb, mrb_value self)
if (p->imaginary != 0) {
mrb_raisef(mrb, E_RANGE_ERROR, "can't convert %v into Float", self);
}
- return mrb_int_value(mrb, p->real);
+ return mrb_int_value(mrb, (mrb_int)p->real);
}
static mrb_value
@@ -224,7 +224,7 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb)
#ifdef COMPLEX_USE_ISTRUCT
mrb_assert(sizeof(struct mrb_complex) < ISTRUCT_DATA_SIZE);
#endif
- comp = mrb_define_class(mrb, "Complex", mrb_class_get(mrb, "Numeric"));
+ comp = mrb_define_class(mrb, "Complex", mrb_class_get_id(mrb, MRB_SYM(Numeric)));
#ifdef COMPLEX_USE_ISTRUCT
MRB_SET_INSTANCE_TT(comp, MRB_TT_ISTRUCT);
#else
diff --git a/mrbgems/mruby-complex/test/complex.rb b/mrbgems/mruby-complex/test/complex.rb
index d996e8277..8f9634048 100644
--- a/mrbgems/mruby-complex/test/complex.rb
+++ b/mrbgems/mruby-complex/test/complex.rb
@@ -56,11 +56,11 @@ end
assert 'Complex#/' do
assert_complex Complex(2, 3) / Complex(2, 3) , (1 + 0i)
assert_complex Complex(900) / Complex(1) , (900 + 0i)
- assert_complex Complex(-2, 9) / Complex(-9, 2), ((36 / 85) - (77i / 85))
- assert_complex Complex(9, 8) / 4 , ((9 / 4) + 2i)
+ assert_complex Complex(-2, 9) / Complex(-9, 2), ((36.0 / 85) - (77i / 85))
+ assert_complex Complex(9, 8) / 4 , ((9.0 / 4) + 2i)
assert_complex Complex(20, 9) / 9.8 , (2.0408163265306123 + 0.9183673469387754i)
if 1e39.infinite? then
- # MRB_USE_FLOAT in effect
+ # MRB_USE_FLOAT32 in effect
ten = 1e21
one = 1e20
else
@@ -80,7 +80,7 @@ assert 'Complex#abs' do
assert_float Complex(-1).abs, 1
assert_float Complex(3.0, -4.0).abs, 5.0
if 1e39.infinite? then
- # MRB_USE_FLOAT in effect
+ # MRB_USE_FLOAT32 in effect
exp = 125
else
exp = 1021