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
ecc77829
Commit
ecc77829
authored
Aug 26, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2562 from cubicdaiya/issues/pow_flo
Fix and add test for Numeric#pow behavior.
parents
b01b3c44
bd6dc0da
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
3 deletions
+12
-3
src/numeric.c
src/numeric.c
+4
-3
test/t/numeric.rb
test/t/numeric.rb
+8
-0
No files found.
src/numeric.c
View file @
ecc77829
...
@@ -54,11 +54,12 @@ static mrb_value
...
@@ -54,11 +54,12 @@ static mrb_value
num_pow
(
mrb_state
*
mrb
,
mrb_value
x
)
num_pow
(
mrb_state
*
mrb
,
mrb_value
x
)
{
{
mrb_value
y
;
mrb_value
y
;
mrb_float
d
;
mrb_float
d
,
yv
;
mrb_get_args
(
mrb
,
"o"
,
&
y
);
mrb_get_args
(
mrb
,
"o"
,
&
y
);
d
=
pow
(
mrb_to_flo
(
mrb
,
x
),
mrb_to_flo
(
mrb
,
y
));
yv
=
mrb_to_flo
(
mrb
,
y
);
if
(
mrb_fixnum_p
(
x
)
&&
mrb_fixnum_p
(
y
)
&&
FIXABLE
(
d
))
d
=
pow
(
mrb_to_flo
(
mrb
,
x
),
yv
);
if
(
mrb_fixnum_p
(
x
)
&&
mrb_fixnum_p
(
y
)
&&
FIXABLE
(
d
)
&&
yv
>
0
)
return
mrb_fixnum_value
((
mrb_int
)
d
);
return
mrb_fixnum_value
((
mrb_int
)
d
);
return
mrb_float_value
(
mrb
,
d
);
return
mrb_float_value
(
mrb
,
d
);
}
}
...
...
test/t/numeric.rb
View file @
ecc77829
...
@@ -18,6 +18,14 @@ assert('Numeric#abs', '15.2.7.4.3') do
...
@@ -18,6 +18,14 @@ assert('Numeric#abs', '15.2.7.4.3') do
assert_equal
(
1.0
,
-
1
.
abs
)
assert_equal
(
1.0
,
-
1
.
abs
)
end
end
assert
(
'Numeric#pow'
)
do
assert_equal
(
8
,
2
**
3
)
assert_equal
(
-
8
,
-
2
**
3
)
assert_equal
(
1
,
2
**
0
)
assert_equal
(
1
,
2.2
**
0
)
assert_equal
(
0.5
,
2
**
-
1
)
end
assert
(
'Numeric#/'
,
'15.2.8.3.4'
)
do
assert
(
'Numeric#/'
,
'15.2.8.3.4'
)
do
n
=
Class
.
new
(
Numeric
){
def
/
(
x
);
15.1
;
end
}.
new
n
=
Class
.
new
(
Numeric
){
def
/
(
x
);
15.1
;
end
}.
new
...
...
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