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
223defd6
Commit
223defd6
authored
May 17, 2019
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move `Numeric#div` to the core.
parent
3734c53e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb
mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb
+0
-4
src/numeric.c
src/numeric.c
+20
-0
No files found.
mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb
View file @
223defd6
module
Integral
module
Integral
def
div
(
other
)
self
.
divmod
(
other
)[
0
]
end
def
zero?
def
zero?
self
==
0
self
==
0
end
end
...
...
src/numeric.c
View file @
223defd6
...
@@ -136,6 +136,25 @@ mrb_num_div(mrb_state *mrb, mrb_value x, mrb_value y)
...
@@ -136,6 +136,25 @@ mrb_num_div(mrb_state *mrb, mrb_value x, mrb_value y)
#endif
#endif
}
}
static
mrb_value
num_idiv
(
mrb_state
*
mrb
,
mrb_value
x
)
{
#ifdef MRB_WITHOUT_FLOAT
mrb_value
y
;
mrb_get_args
(
mrb
,
"o"
,
&
y
);
if
(
!
mrb_fixnum_p
(
y
))
{
mrb_raise
(
mrb
,
E_TYPE_ERROR
,
"non fixnum value"
);
}
return
mrb_fixnum_value
(
mrb_fixnum
(
x
)
/
mrb_fixnum
(
y
));
#else
mrb_float
y
;
mrb_get_args
(
mrb
,
"f"
,
&
y
);
return
mrb_int_value
(
mrb
,
mrb_to_flo
(
mrb
,
x
)
/
y
);
#endif
}
/* 15.2.9.3.19(x) */
/* 15.2.9.3.19(x) */
/*
/*
* call-seq:
* call-seq:
...
@@ -1552,6 +1571,7 @@ mrb_init_numeric(mrb_state *mrb)
...
@@ -1552,6 +1571,7 @@ mrb_init_numeric(mrb_state *mrb)
mrb_define_method
(
mrb
,
numeric
,
"**"
,
num_pow
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
numeric
,
"**"
,
num_pow
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
numeric
,
"/"
,
num_div
,
MRB_ARGS_REQ
(
1
));
/* 15.2.8.3.4 */
mrb_define_method
(
mrb
,
numeric
,
"/"
,
num_div
,
MRB_ARGS_REQ
(
1
));
/* 15.2.8.3.4 */
mrb_define_method
(
mrb
,
numeric
,
"quo"
,
num_div
,
MRB_ARGS_REQ
(
1
));
/* 15.2.7.4.5 (x) */
mrb_define_method
(
mrb
,
numeric
,
"quo"
,
num_div
,
MRB_ARGS_REQ
(
1
));
/* 15.2.7.4.5 (x) */
mrb_define_method
(
mrb
,
numeric
,
"div"
,
num_idiv
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
numeric
,
"<=>"
,
num_cmp
,
MRB_ARGS_REQ
(
1
));
/* 15.2.9.3.6 */
mrb_define_method
(
mrb
,
numeric
,
"<=>"
,
num_cmp
,
MRB_ARGS_REQ
(
1
));
/* 15.2.9.3.6 */
mrb_define_method
(
mrb
,
numeric
,
"<"
,
num_lt
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
numeric
,
"<"
,
num_lt
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
numeric
,
"<="
,
num_le
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
numeric
,
"<="
,
num_le
,
MRB_ARGS_REQ
(
1
));
...
...
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