Re: WP-34S (Prime Number Test) question Message #4 Posted by Dieter on 20 Oct 2013, 5:28 p.m., in response to message #3 by Barry Mead
Quote:
For instance the Even? and Odd? tests show false for numbers like 78.1 and 79.1, although the underlying integer 78 and 79 are Even and Odd respectively
Yes, that's the way these functions are supposed to work. Take a look at the manual (IOP):
EVEN? Checks if x is integer and even
ODD? Checks if x is integer and odd
Thus any non-integer will return "false" here.
Compare this with what the manual states for the PRIME? function:
PRIME? Checks if the absolute value of the integer part of x is prime.
That's why 78,9999... tests false. The integer part of x is 78, and 78 is not prime.
So PRIME? tests if the integer part of x (!) is prime, while ODD? and EVEN? first test if x is an integer at all, and only if it is, they test if this integer is odd resp. even.
So yes, you are right: not all functions work on the full-precision value of X. Some ignore the sign and fractional part of X, such as the PRIME? function. But they do not round to the next integer either.
Dieter
Edited: 20 Oct 2013, 5:32 p.m.
|