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
fa3ac351
Unverified
Commit
fa3ac351
authored
4 years ago
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complex.c: override float division to support `Complex`.
parent
afb3c00e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
mrbgems/mruby-complex/src/complex.c
mrbgems/mruby-complex/src/complex.c
+20
-0
No files found.
mrbgems/mruby-complex/src/complex.c
View file @
fa3ac351
...
...
@@ -348,6 +348,24 @@ int_quo(mrb_state *mrb, mrb_value x)
}
#endif
static
mrb_value
flo_div
(
mrb_state
*
mrb
,
mrb_value
x
)
{
mrb_float
a
=
mrb_float
(
x
);
mrb_value
y
=
mrb_get_arg1
(
mrb
);
switch
(
mrb_type
(
y
))
{
case
MRB_TT_COMPLEX
:
return
complex_div
(
mrb
,
complex_new
(
mrb
,
a
,
0
));
case
MRB_TT_FLOAT
:
a
=
div_flo
(
a
,
mrb_float
(
y
));
return
mrb_float_value
(
mrb
,
a
);
default:
a
=
div_flo
(
a
,
mrb_to_flo
(
mrb
,
y
));
return
mrb_float_value
(
mrb
,
a
);
}
}
void
mrb_mruby_complex_gem_init
(
mrb_state
*
mrb
)
{
struct
RClass
*
comp
;
...
...
@@ -376,6 +394,8 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb)
mrb_define_method
(
mrb
,
mrb
->
integer_class
,
"/"
,
int_div
,
MRB_ARGS_REQ
(
1
));
/* overrride */
mrb_define_method
(
mrb
,
mrb
->
integer_class
,
"quo"
,
int_quo
,
MRB_ARGS_REQ
(
1
));
/* overrride */
#endif
mrb_define_method
(
mrb
,
mrb
->
float_class
,
"/"
,
flo_div
,
MRB_ARGS_REQ
(
1
));
/* overrride */
mrb_define_method
(
mrb
,
mrb
->
float_class
,
"quo"
,
flo_div
,
MRB_ARGS_REQ
(
1
));
/* overrride */
}
void
...
...
This diff is collapsed.
Click to expand it.
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