From: Robert Dober Date: 2009-03-08T02:36:59+09:00 Subject: [ruby-core:22720] Re: [Bug #1243] 1 is prime On Fri, Mar 6, 2009 at 8:42 PM, Jacob Fugal wrote: > I have a hard time imagining a situation where asking if a negative > number is prime would be necessary. Code the cares about prime numbers > almost by design implies that it expects positive integers. In that > mindset, I call YAGNI. > > There is no compelling argument (to me) to have the Ruby standard > library definition of prime be inconsistent with the mathematical > definition. A prime number -- not a prime factor or a prime element of > the ring of integers or a prime element of any other arbitrary ring -- > is a natural number (that is, a positive -- or non-negative, it > doesn't matter here -- integer) which has exactly two distinct natural > number divisors: 1 and itself. 1 is not prime and negative integers > are not prime. Rationals or Floats not coinciding with an integer are > not prime. That should be the definition of "prime?". > > In the rare case where someone does need to check if the absolute > value of a negative integer x is prime, x.abs.prime? is not a horrible > burden, and it reveals the intent that negative numbers are acceptable > input to boot. > > Jacob Fugal > > I tend to agree, I was taken away by the "challenge" to find a meaningful definition for primes < 0. And when I failed to do so I asked for help, stupid somehow, is it not, LOL. Cheers Robert