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
3a462fe4
Commit
3a462fe4
authored
Sep 02, 2015
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integer << and >> to use Float instead of raising RangeError
parent
74696ffd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
15 deletions
+7
-15
src/numeric.c
src/numeric.c
+7
-5
test/t/integer.rb
test/t/integer.rb
+0
-10
No files found.
src/numeric.c
View file @
3a462fe4
...
@@ -820,11 +820,13 @@ fix_xor(mrb_state *mrb, mrb_value x)
...
@@ -820,11 +820,13 @@ fix_xor(mrb_state *mrb, mrb_value x)
static
mrb_value
static
mrb_value
lshift
(
mrb_state
*
mrb
,
mrb_int
val
,
mrb_int
width
)
lshift
(
mrb_state
*
mrb
,
mrb_int
val
,
mrb_int
width
)
{
{
mrb_assert
(
width
>
=
0
);
mrb_assert
(
width
>
0
);
if
(
width
>
NUMERIC_SHIFT_WIDTH_MAX
)
{
if
(
width
>
NUMERIC_SHIFT_WIDTH_MAX
)
{
mrb_raisef
(
mrb
,
E_RANGE_ERROR
,
"width(%S) > (%S:MRB_INT_BIT-1)"
,
mrb_float
f
=
(
mrb_float
)
val
;
mrb_fixnum_value
(
width
),
while
(
width
--
)
{
mrb_fixnum_value
(
NUMERIC_SHIFT_WIDTH_MAX
));
f
*=
2
;
}
return
mrb_float_value
(
mrb
,
f
);
}
}
return
mrb_fixnum_value
(
val
<<
width
);
return
mrb_fixnum_value
(
val
<<
width
);
}
}
...
@@ -832,7 +834,7 @@ lshift(mrb_state *mrb, mrb_int val, mrb_int width)
...
@@ -832,7 +834,7 @@ lshift(mrb_state *mrb, mrb_int val, mrb_int width)
static
mrb_value
static
mrb_value
rshift
(
mrb_int
val
,
mrb_int
width
)
rshift
(
mrb_int
val
,
mrb_int
width
)
{
{
mrb_assert
(
width
>
=
0
);
mrb_assert
(
width
>
0
);
if
(
width
>=
NUMERIC_SHIFT_WIDTH_MAX
)
{
if
(
width
>=
NUMERIC_SHIFT_WIDTH_MAX
)
{
if
(
val
<
0
)
{
if
(
val
<
0
)
{
return
mrb_fixnum_value
(
-
1
);
return
mrb_fixnum_value
(
-
1
);
...
...
test/t/integer.rb
View file @
3a462fe4
...
@@ -147,11 +147,6 @@ assert('Integer#<<', '15.2.8.3.12') do
...
@@ -147,11 +147,6 @@ assert('Integer#<<', '15.2.8.3.12') do
# Left Shift by a negative is Right Shift
# Left Shift by a negative is Right Shift
assert_equal
23
,
46
<<
-
1
assert_equal
23
,
46
<<
-
1
# Raise when shift is too large
assert_raise
(
RangeError
)
do
2
<<
128
end
end
end
assert
(
'Integer#>>'
,
'15.2.8.3.13'
)
do
assert
(
'Integer#>>'
,
'15.2.8.3.13'
)
do
...
@@ -165,11 +160,6 @@ assert('Integer#>>', '15.2.8.3.13') do
...
@@ -165,11 +160,6 @@ assert('Integer#>>', '15.2.8.3.13') do
# Don't raise on large Right Shift
# Don't raise on large Right Shift
assert_equal
0
,
23
>>
128
assert_equal
0
,
23
>>
128
# Raise when shift is too large
assert_raise
(
RangeError
)
do
2
>>
-
128
end
end
end
assert
(
'Integer#ceil'
,
'15.2.8.3.14'
)
do
assert
(
'Integer#ceil'
,
'15.2.8.3.14'
)
do
...
...
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