![]() |
WP-34S (Prime Number Test) question - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: WP-34S (Prime Number Test) question (/thread-253323.html) |
WP-34S (Prime Number Test) question - Barry Mead - 10-20-2013 I looked into how the Prime? test works, and essentially it takes
For example if you take the number 79 and divide it by 3 then multiply it by 3, you get a number with a tiny rounding error
So the primality test (h test prime?) clips it down to 78 and shows false. If the RND(X) were applied to the number prior to testing for
Edited: 20 Oct 2013, 3:06 p.m.
Re: WP-34S (Prime Number Test) question - Dieter - 10-20-2013 All numerical functions always work with the exact, unrounded argument in (usually) X. And I think it's fine this way. Consider your example with the 78,99999999999999 that is displayed as 79 since you do not see the last four digits. Now subtract 79 from this. Should the 34s display zero? Of course it shouldn't. And that's why it shouldn't claim 78,99999999999999 is prime either, or maybe even INT(x) = 79 just because that's what you see in the display.
Dieter
Re: WP-34S (Prime Number Test) question - Barry Mead - 10-20-2013 That is not exactly true. For instance the Even? and Odd? tests Re: WP-34S (Prime Number Test) question - Dieter - 10-20-2013 Quote: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 evenThus 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.
|