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
c088af87
Unverified
Commit
c088af87
authored
Jan 05, 2022
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
object.c: Call functions directly from `mrb_ensure_int_type()`; #5622
parent
d34e1cb8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
10 deletions
+32
-10
mrbgems/mruby-complex/src/complex.c
mrbgems/mruby-complex/src/complex.c
+4
-4
mrbgems/mruby-rational/src/rational.c
mrbgems/mruby-rational/src/rational.c
+3
-3
src/object.c
src/object.c
+25
-3
No files found.
mrbgems/mruby-complex/src/complex.c
View file @
c088af87
...
@@ -117,13 +117,13 @@ mrb_complex_to_f(mrb_state *mrb, mrb_value self)
...
@@ -117,13 +117,13 @@ mrb_complex_to_f(mrb_state *mrb, mrb_value self)
return
mrb_float_value
(
mrb
,
p
->
real
);
return
mrb_float_value
(
mrb
,
p
->
real
);
}
}
static
mrb_value
mrb_value
complex_to_i
(
mrb_state
*
mrb
,
mrb_value
self
)
mrb_
complex_to_i
(
mrb_state
*
mrb
,
mrb_value
self
)
{
{
struct
mrb_complex
*
p
=
complex_ptr
(
mrb
,
self
);
struct
mrb_complex
*
p
=
complex_ptr
(
mrb
,
self
);
if
(
p
->
imaginary
!=
0
)
{
if
(
p
->
imaginary
!=
0
)
{
mrb_raisef
(
mrb
,
E_RANGE_ERROR
,
"can't convert %v into
Float
"
,
self
);
mrb_raisef
(
mrb
,
E_RANGE_ERROR
,
"can't convert %v into
Integer
"
,
self
);
}
}
return
mrb_int_value
(
mrb
,
(
mrb_int
)
p
->
real
);
return
mrb_int_value
(
mrb
,
(
mrb_int
)
p
->
real
);
}
}
...
@@ -416,7 +416,7 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb)
...
@@ -416,7 +416,7 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb)
mrb_define_method
(
mrb
,
comp
,
"real"
,
complex_real
,
MRB_ARGS_NONE
());
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
,
"imaginary"
,
complex_imaginary
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
comp
,
"to_f"
,
mrb_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_i"
,
mrb_
complex_to_i
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
comp
,
"to_c"
,
complex_to_c
,
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
));
mrb_define_method
(
mrb
,
comp
,
"+"
,
complex_add
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
comp
,
"-"
,
complex_sub
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
comp
,
"-"
,
complex_sub
,
MRB_ARGS_REQ
(
1
));
...
...
mrbgems/mruby-rational/src/rational.c
View file @
c088af87
...
@@ -299,8 +299,8 @@ mrb_rational_to_f(mrb_state *mrb, mrb_value self)
...
@@ -299,8 +299,8 @@ mrb_rational_to_f(mrb_state *mrb, mrb_value self)
}
}
#endif
#endif
static
mrb_value
mrb_value
rational_to_i
(
mrb_state
*
mrb
,
mrb_value
self
)
mrb_
rational_to_i
(
mrb_state
*
mrb
,
mrb_value
self
)
{
{
struct
mrb_rational
*
p
=
rational_ptr
(
mrb
,
self
);
struct
mrb_rational
*
p
=
rational_ptr
(
mrb
,
self
);
if
(
p
->
denominator
==
0
)
{
if
(
p
->
denominator
==
0
)
{
...
@@ -714,7 +714,7 @@ void mrb_mruby_rational_gem_init(mrb_state *mrb)
...
@@ -714,7 +714,7 @@ void mrb_mruby_rational_gem_init(mrb_state *mrb)
#ifndef MRB_NO_FLOAT
#ifndef MRB_NO_FLOAT
mrb_define_method
(
mrb
,
rat
,
"to_f"
,
mrb_rational_to_f
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
rat
,
"to_f"
,
mrb_rational_to_f
,
MRB_ARGS_NONE
());
#endif
#endif
mrb_define_method
(
mrb
,
rat
,
"to_i"
,
rational_to_i
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
rat
,
"to_i"
,
mrb_
rational_to_i
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
rat
,
"to_r"
,
rational_to_r
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
rat
,
"to_r"
,
rational_to_r
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
rat
,
"negative?"
,
rational_negative_p
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
rat
,
"negative?"
,
rational_negative_p
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
rat
,
"=="
,
rational_eq
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
rat
,
"=="
,
rational_eq
,
MRB_ARGS_REQ
(
1
));
...
...
src/object.c
View file @
c088af87
...
@@ -484,6 +484,17 @@ mrb_obj_is_kind_of(mrb_state *mrb, mrb_value obj, struct RClass *c)
...
@@ -484,6 +484,17 @@ mrb_obj_is_kind_of(mrb_state *mrb, mrb_value obj, struct RClass *c)
return
FALSE
;
return
FALSE
;
}
}
#ifdef MRB_USE_RATIONAL
// provided by mruby-rational with MRB_USE_RATIONAL
mrb_value
mrb_rational_to_i
(
mrb_state
*
mrb
,
mrb_value
rat
);
mrb_value
mrb_rational_to_f
(
mrb_state
*
mrb
,
mrb_value
rat
);
#endif
#ifdef MRB_USE_COMPLEX
// provided by mruby-complex with MRB_USE_COMPLEX
mrb_value
mrb_complex_to_f
(
mrb_state
*
mrb
,
mrb_value
comp
);
mrb_value
mrb_complex_to_i
(
mrb_state
*
mrb
,
mrb_value
comp
);
#endif
MRB_API
mrb_value
MRB_API
mrb_value
mrb_ensure_int_type
(
mrb_state
*
mrb
,
mrb_value
val
)
mrb_ensure_int_type
(
mrb_state
*
mrb
,
mrb_value
val
)
{
{
...
@@ -492,6 +503,20 @@ mrb_ensure_int_type(mrb_state *mrb, mrb_value val)
...
@@ -492,6 +503,20 @@ mrb_ensure_int_type(mrb_state *mrb, mrb_value val)
if
(
mrb_float_p
(
val
))
{
if
(
mrb_float_p
(
val
))
{
return
mrb_float_to_integer
(
mrb
,
val
);
return
mrb_float_to_integer
(
mrb
,
val
);
}
}
else
{
switch
(
mrb_type
(
val
))
{
#ifdef MRB_USE_RATIONAL
case
MRB_TT_RATIONAL
:
return
mrb_rational_to_i
(
mrb
,
val
);
#endif
#ifdef MRB_USE_COMPLEX
case
MRB_TT_COMPLEX
:
return
mrb_complex_to_i
(
mrb
,
val
);
#endif
default:
break
;
}
}
#endif
#endif
mrb_raisef
(
mrb
,
E_TYPE_ERROR
,
"%Y cannot be converted to Integer"
,
val
);
mrb_raisef
(
mrb
,
E_TYPE_ERROR
,
"%Y cannot be converted to Integer"
,
val
);
}
}
...
@@ -499,9 +524,6 @@ mrb_ensure_int_type(mrb_state *mrb, mrb_value val)
...
@@ -499,9 +524,6 @@ mrb_ensure_int_type(mrb_state *mrb, mrb_value val)
}
}
#ifndef MRB_NO_FLOAT
#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_API
mrb_value
mrb_ensure_float_type
(
mrb_state
*
mrb
,
mrb_value
val
)
mrb_ensure_float_type
(
mrb_state
*
mrb
,
mrb_value
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