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

* lib/prime.rb (Prime#prime_division): now decomposes

negative integer into a decomposition with element [-1, 1].

* test/test_prime.rb: test for it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
yugui 2009-07-13 13:51:49 +00:00
parent 0fefd19023
commit 7287b852da
3 changed files with 18 additions and 1 deletions

View file

@ -194,7 +194,12 @@ class Prime
#
def prime_division(value, generator= Prime::Generator23.new)
raise ZeroDivisionError if value == 0
pv = []
if value < 0
value = -value
pv = [[-1, 1]]
else
pv = []
end
for prime in generator
count = 0
while (value1, mod = value.divmod(prime)