Primality by trial division: Difference between revisions

→‎{{header|Ada}}: expression function
(→‎{{header|Ada}}: algorithm improperly states 1 as prime)
(→‎{{header|Ada}}: expression function)
Line 459:
<code>Sqrt</code> is made visible by a with / use clause on <code>Ada.Numerics.Elementary_Functions</code>.
 
With Ada 2012, the function can be made more compact as an expression function (but without loop optimized by skipping even numbers) :
<lang ada>function Is_Prime(Item : Positive) return Boolean is
(Item /= 1 and then
(for all Test in 2..Integer(Sqrt(Float(Item))) => Item mod Test /= 0));</lang>
As an alternative, one can use the generic function Prime_Numbers.Is_Prime, as specified in [[Prime decomposition#Ada]], which also implements trial division.
<lang Ada>with Prime_Numbers;