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
74696ffd
Commit
74696ffd
authored
Sep 02, 2015
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Float << and >> should be more compatible to Fixnum
parent
6ddd79fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
4 deletions
+44
-4
mrblib/numeric.rb
mrblib/numeric.rb
+22
-4
test/t/float.rb
test/t/float.rb
+22
-0
No files found.
mrblib/numeric.rb
View file @
74696ffd
...
...
@@ -165,12 +165,30 @@ class Float
# floats should be compatible to integers.
def
>>
other
n
=
self
.
to_i
other
.
to_i
.
times
{
n
/=
2
}
n
other
=
other
.
to_i
if
other
<
0
n
<<
-
other
else
other
.
times
{
n
/=
2
}
if
n
.
abs
<
1
if
n
>=
0
0
else
-
1
end
else
n
.
to_i
end
end
end
def
<<
other
n
=
self
.
to_i
other
.
to_i
.
times
{
n
*=
2
}
n
.
to_i
other
=
other
.
to_i
if
other
<
0
n
>>
-
other
else
other
.
times
{
n
*=
2
}
n
end
end
end
test/t/float.rb
View file @
74696ffd
...
...
@@ -178,3 +178,25 @@ assert('Float#nan?') do
assert_false
(
1.0
/
0.0
).
nan?
assert_false
(
-
1.0
/
0.0
).
nan?
end
assert
(
'Float#<<'
)
do
# Left Shift by one
assert_equal
46
,
23.0
<<
1
# Left Shift by a negative is Right Shift
assert_equal
23
,
46.0
<<
-
1
end
assert
(
'Float#>>'
)
do
# Right Shift by one
assert_equal
23
,
46.0
>>
1
# Right Shift by a negative is Left Shift
assert_equal
46
,
23.0
>>
-
1
# Don't raise on large Right Shift
assert_equal
0
,
23.0
>>
128
# Don't raise on large Right Shift
assert_equal
-
1
,
-
23.0
>>
128
end
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