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
4e0b1622
Unverified
Commit
4e0b1622
authored
Jan 02, 2022
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Jan 02, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5622 from dearblue/to_f
Call functions directly from `mrb_ensure_float_type()`
parents
ab4baba2
ac22a63a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
8 deletions
+32
-8
mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c
mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c
+15
-0
mrbgems/mruby-complex/src/complex.c
mrbgems/mruby-complex/src/complex.c
+3
-3
mrbgems/mruby-rational/src/rational.c
mrbgems/mruby-rational/src/rational.c
+4
-4
src/object.c
src/object.c
+10
-1
No files found.
mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c
View file @
4e0b1622
...
...
@@ -366,3 +366,18 @@ mrb_final_mrbgems(mrb_state *mrb)
{
}
#endif
#ifdef MRB_USE_COMPLEX
mrb_value
mrb_complex_to_f
(
mrb_state
*
mrb
,
mrb_value
comp
)
{
mrb_raise
(
mrb
,
E_NOTIMP_ERROR
,
"unavailable for core only"
);
}
#endif
#ifdef MRB_USE_RATIONAL
mrb_value
mrb_rational_to_f
(
mrb_state
*
mrb
,
mrb_value
rat
)
{
mrb_raise
(
mrb
,
E_NOTIMP_ERROR
,
"unavailable for core only"
);
}
#endif
mrbgems/mruby-complex/src/complex.c
View file @
4e0b1622
...
...
@@ -105,8 +105,8 @@ complex_s_rect(mrb_state *mrb, mrb_value self)
return
complex_new
(
mrb
,
real
,
imaginary
);
}
static
mrb_value
complex_to_f
(
mrb_state
*
mrb
,
mrb_value
self
)
mrb_value
mrb_
complex_to_f
(
mrb_state
*
mrb
,
mrb_value
self
)
{
struct
mrb_complex
*
p
=
complex_ptr
(
mrb
,
self
);
...
...
@@ -415,7 +415,7 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb)
mrb_define_method
(
mrb
,
mrb
->
kernel_module
,
"Complex"
,
complex_s_rect
,
MRB_ARGS_REQ
(
1
)
|
MRB_ARGS_OPT
(
1
));
mrb_define_method
(
mrb
,
comp
,
"real"
,
complex_real
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
comp
,
"imaginary"
,
complex_imaginary
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
comp
,
"to_f"
,
complex_to_f
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
comp
,
"to_f"
,
mrb_
complex_to_f
,
MRB_ARGS_NONE
());
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_add
,
MRB_ARGS_REQ
(
1
));
...
...
mrbgems/mruby-rational/src/rational.c
View file @
4e0b1622
...
...
@@ -291,8 +291,8 @@ rat_float(struct mrb_rational *p)
return
f
;
}
static
mrb_value
rational_to_f
(
mrb_state
*
mrb
,
mrb_value
self
)
mrb_value
mrb_
rational_to_f
(
mrb_state
*
mrb
,
mrb_value
self
)
{
struct
mrb_rational
*
p
=
rational_ptr
(
mrb
,
self
);
return
mrb_float_value
(
mrb
,
rat_float
(
p
));
...
...
@@ -394,7 +394,7 @@ rational_eq(mrb_state *mrb, mrb_value x)
case
MRB_TT_COMPLEX
:
{
mrb_bool
mrb_complex_eq
(
mrb_state
*
mrb
,
mrb_value
,
mrb_value
);
result
=
mrb_complex_eq
(
mrb
,
y
,
rational_to_f
(
mrb
,
x
));
result
=
mrb_complex_eq
(
mrb
,
y
,
mrb_
rational_to_f
(
mrb
,
x
));
break
;
}
#endif
...
...
@@ -712,7 +712,7 @@ void mrb_mruby_rational_gem_init(mrb_state *mrb)
mrb_define_method
(
mrb
,
rat
,
"numerator"
,
rational_numerator
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
rat
,
"denominator"
,
rational_denominator
,
MRB_ARGS_NONE
());
#ifndef MRB_NO_FLOAT
mrb_define_method
(
mrb
,
rat
,
"to_f"
,
rational_to_f
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
rat
,
"to_f"
,
mrb_
rational_to_f
,
MRB_ARGS_NONE
());
#endif
mrb_define_method
(
mrb
,
rat
,
"to_i"
,
rational_to_i
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
rat
,
"to_r"
,
rational_to_r
,
MRB_ARGS_NONE
());
...
...
src/object.c
View file @
4e0b1622
...
...
@@ -499,6 +499,9 @@ mrb_ensure_int_type(mrb_state *mrb, mrb_value val)
}
#ifndef MRB_NO_FLOAT
mrb_value
mrb_complex_to_f
(
mrb_state
*
mrb
,
mrb_value
comp
);
// provided by mruby-complex with MRB_USE_COMPLEX
mrb_value
mrb_rational_to_f
(
mrb_state
*
mrb
,
mrb_value
rat
);
// provided by mruby-rational with MRB_USE_RATIONAL
MRB_API
mrb_value
mrb_ensure_float_type
(
mrb_state
*
mrb
,
mrb_value
val
)
{
...
...
@@ -512,9 +515,15 @@ mrb_ensure_float_type(mrb_state *mrb, mrb_value val)
case
MRB_TT_FLOAT
:
return
val
;
#ifdef MRB_USE_RATIONAL
case
MRB_TT_RATIONAL
:
return
mrb_rational_to_f
(
mrb
,
val
);
#endif
#ifdef MRB_USE_COMPLEX
case
MRB_TT_COMPLEX
:
return
mrb_type_convert
(
mrb
,
val
,
MRB_TT_FLOAT
,
MRB_SYM
(
to_f
));
return
mrb_complex_to_f
(
mrb
,
val
);
#endif
default:
mrb_raisef
(
mrb
,
E_TYPE_ERROR
,
"%Y cannot be converted to Float"
,
val
);
...
...
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