Bug #7395

Negative numbers can't be primes by definition

Added by Zachary Scott over 2 years ago. Updated 9 months ago.

[ruby-core:49558]
Status:Closed
Priority:Normal
Assignee:Yuki Sonoda
ruby -v:2.0.0 Backport:

Description

from github:
https://github.com/ruby/ruby/pull/187

By definition, a prime number can be a positive integer greater than 1.

http://mathworld.wolfram.com/PrimeNumber.html

prime_refute_negative_numbers.patch Magnifier (1.16 KB) Zachary Scott, 11/19/2012 12:40 PM

Associated revisions

Revision 45878
Added by Ayumu AIZAWA 10 months ago

  • lib/prime.rb (Prime#prime?): negative numbers can't be primes by definition. reported by Ivan Kataitsev. [Bug #7395]
  • test/test_prime.rb: add test.

Revision 45878
Added by Ayumu AIZAWA 10 months ago

  • lib/prime.rb (Prime#prime?): negative numbers can't be primes by definition. reported by Ivan Kataitsev. [Bug #7395]
  • test/test_prime.rb: add test.

Revision 46061
Added by Ayumu AIZAWA 9 months ago

add information of incompatibility about Prime.prime? [Bug #7395]

Revision 46061
Added by Ayumu AIZAWA 9 months ago

add information of incompatibility about Prime.prime? [Bug #7395]

History

#1 Updated by Usaku NAKAMURA about 2 years ago

  • Status changed from Open to Assigned

#2 Updated by Koichi Sasada about 2 years ago

  • Subject changed from Negative numbers can't be primes by definition to Negative numbers can't be primes by definition
  • Target version changed from 2.0.0 to 2.1.0

#3 Updated by Hiroshi SHIBATA about 1 year ago

  • Target version changed from 2.1.0 to current: 2.2.0

#4 Updated by Ayumu AIZAWA 10 months ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

Applied in changeset r45878.


  • lib/prime.rb (Prime#prime?): negative numbers can't be primes by definition. reported by Ivan Kataitsev. [Bug #7395]
  • test/test_prime.rb: add test.

#5 Updated by Hiroshi SHIBATA 10 months ago

ayumin

this issue seems incompatible changes. it should be add NEWS.

#6 Updated by Yusuke Endoh 10 months ago

  • Status changed from Closed to Assigned

Read the rdoc carefully:

Returns true if +self+ is a prime number, false for a composite.

By definition, a composite number can be also a positive integer greater than 1.

http://mathworld.wolfram.com/CompositeNumber.html

Thus,

1.prime? #=> false
0.prime? #=> false
(-1).prime? #=> false

looks all buggy (or undefined behavior) to me.
If we can change the spec, it would be good to raise an exception, return nil, or at least update the rdoc.
Anyway, the maintainer (Yugui) should treat this, I think.

Yusuke Endoh mame@tsg.ne.jp

#7 Updated by Ayumu AIZAWA 10 months ago

Endo-san

Your opinion seems right.

IMHO, I think Rdoc should be updated.
This method should evaluate the number is prime number or not.
It should not refer the number is composite number or not.

We may have to confirm Yugui's intention anyway.
Luckily I'm going to meet her on Wed, so I will ask her about this issue.

Shibata-san
I will add information to NEWS, once change was accepted by Yugui.

#8 Updated by Ayumu AIZAWA 9 months ago

  • Status changed from Assigned to Closed

Applied in changeset r46061.


add information of incompatibility about Prime.prime? [Bug #7395]

Also available in: Atom PDF