mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00

1**n => 1, -1**n => 1 (n: even) / -1 (n: odd). * test/ruby/test_fixnum.rb (TestFixnum::test_pow): update test suite. pow(-3, 2^64) gives NaN when pow(3, 2^64) gives Inf. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
26 lines
438 B
Ruby
26 lines
438 B
Ruby
require 'test/unit'
|
|
|
|
class TestFixnum < Test::Unit::TestCase
|
|
def setup
|
|
@verbose = $VERBOSE
|
|
$VERBOSE = nil
|
|
end
|
|
|
|
def teardown
|
|
$VERBOSE = @verbose
|
|
end
|
|
|
|
def test_pow
|
|
[1, 2, 2**64, 2**63*3, 2**64*3].each do |y|
|
|
[-1, 0, 1].each do |x|
|
|
z1 = x**y
|
|
z2 = (-x)**y
|
|
if y % 2 == 1
|
|
assert_equal(z2, -z1)
|
|
else
|
|
assert_equal(z2, z1)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|