Skip to content

Negative numbers can't be primes by definition. #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/prime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def each(ubound = nil, generator = EratosthenesGenerator.new, &block)
# +value+:: an arbitrary integer to be checked.
# +generator+:: optional. A pseudo-prime generator.
def prime?(value, generator = Prime::Generator23.new)
value = -value if value < 0
return false if value < 2
for num in generator
q,r = value.divmod num
Expand Down
4 changes: 2 additions & 2 deletions test/test_prime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def test_prime?

# negative
assert !-1.prime?
assert(-2.prime?)
assert(-3.prime?)
assert !-2.prime?
assert !-3.prime?
assert !-4.prime?
end
end
Expand Down