Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
3deb62d6
Unverified
Commit
3deb62d6
authored
Mar 24, 2021
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complex.c: implement `Complex#/` and `#quo` in C.
parent
5573707d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
12 deletions
+10
-12
mrbgems/mruby-complex/mrblib/complex.rb
mrbgems/mruby-complex/mrblib/complex.rb
+0
-9
mrbgems/mruby-complex/src/complex.c
mrbgems/mruby-complex/src/complex.c
+10
-3
No files found.
mrbgems/mruby-complex/mrblib/complex.rb
View file @
3deb62d6
...
...
@@ -35,15 +35,6 @@ class Complex < Numeric
end
end
def
/
(
rhs
)
if
rhs
.
is_a?
Complex
__div__
(
rhs
)
elsif
rhs
.
is_a?
Numeric
Complex
(
real
/
rhs
,
imaginary
/
rhs
)
end
end
alias_method
:quo
,
:/
def
abs
Math
.
hypot
imaginary
,
real
end
...
...
mrbgems/mruby-complex/src/complex.c
View file @
3deb62d6
...
...
@@ -236,8 +236,15 @@ div_pair(struct float_pair *q, struct float_pair const *a,
static
mrb_value
complex_div
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
rhs
=
mrb_get_arg1
(
mrb
);
struct
mrb_complex
*
a
,
*
b
;
mrb_value
rhs
=
mrb_get_arg1
(
mrb
);
a
=
complex_ptr
(
mrb
,
self
);
if
(
mrb_type
(
rhs
)
!=
MRB_TT_COMPLEX
)
{
mrb_float
f
=
mrb_to_flo
(
mrb
,
rhs
);
return
complex_new
(
mrb
,
a
->
real
/
f
,
a
->
imaginary
/
f
);
}
struct
float_pair
ar
,
ai
,
br
,
bi
;
struct
float_pair
br2
,
bi2
;
struct
float_pair
div
;
...
...
@@ -245,7 +252,6 @@ complex_div(mrb_state *mrb, mrb_value self)
struct
float_pair
ai_br
,
ar_bi
;
struct
float_pair
zr
,
zi
;
a
=
complex_ptr
(
mrb
,
self
);
b
=
complex_ptr
(
mrb
,
rhs
);
/* Split floating point components into significand and exponent */
...
...
@@ -345,7 +351,8 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb)
mrb_define_method
(
mrb
,
comp
,
"to_i"
,
complex_to_i
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
comp
,
"to_c"
,
complex_to_c
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
comp
,
"*"
,
complex_mul
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
comp
,
"__div__"
,
complex_div
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
comp
,
"/"
,
complex_div
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
comp
,
"quo"
,
complex_div
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
comp
,
"=="
,
complex_eq
,
MRB_ARGS_REQ
(
1
));
#ifndef MRB_USE_RATIONAL
mrb_define_method
(
mrb
,
mrb
->
integer_class
,
"/"
,
int_div
,
MRB_ARGS_REQ
(
1
));
/* overrride */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment