Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Bugs nobody cares about, #3

Charles Dye

Super Moderator
May
5,853
217
Staff member
Does anybody use @ISPRIME and @PRIME for anything? Why are they even there?

Code:
C:\>echo %@isprime[%@eval[65537 ** 2]]
1

C:\>echo %@isprime[%@eval[65539 ** 2]]
1

C:\>echo %@isprime[%@eval[65543 ** 2]]
1

C:\>echo %@isprime[%@eval[65537 * 65543]]
1

C:\>

If n is a 64-bit value, then √n must be at least 32 bits. @PRIME is similarly afflicted.

@PRIME also gives false negatives at the high end of its range:

Code:
C:\>echo %@isprime[18446744073709551557]
0

C:\>echo %@isprime[18446744073709551533]
0

C:\>echo %@isprime[18446744073709551521]
0

C:\>

No idea why that's happening....
 
About ...
Code:
echo %@isprime[x]

x seems only valid for SIGNED int64 and not uint64 (unsigned), means till 9223372036854775807 (2^63 - 1).

biggest int64 signed prime is:
Code:
ag-usr@AG-NB_HP-3 >["c:\users\ag-usr\downloads"]
ADM: N | Zeit: 21:59 | $ > echo %@isprime[9223372036854775783]
1

smallest uint64 (unsigned) is:
Code:
ag-usr@AG-NB_HP-3 >["c:\users\ag-usr\downloads"]
ADM: N | Zeit: 22:03 | $ > echo %@isprime[9223372036854775784]
0


About...
Code:
echo %@isprime[%@eval[65537 ** 2]]
for example, I have also no idea!

Code:
echo %@eval[65537 ** 2]
4295098369
is clearly not a prime and not too big for @eval or @isprime ...
 
Last edited:
x seems only valid for SIGNED int64 and not uint64 (unsigned), means till 9223372036854775807 (2^63 - 1).

That would explain my false negatives at the high end. Although why anyone would want to pass negative numbers in this context is not clear to me.

Testing backwards from 2^63-1, I'm only seeing false positives.

About...
Code:
echo %@isprime[%@eval[65537 ** 2]]
for example, I have also no idea!

That only seems to happen when the smallest factor is > 65535. So: Rex is only testing factors in the (unsigned) 16-bit range.
 
In the specific case of %@eval[65537 ** 2] you'll get the wrong answer if you don't test all the way up to (and including) its square root (because 65537 is prime).
 
Ahhhhhhh, yes, Vince, of course!

Thanks for the enlightenment!

Nope, I don't understand, because:

Code:
ag-usr@AG-NB_HP-3 >["c:\users\ag-usr\downloads"]
ADM: N | Zeit: 01:05 | $ > echo %@isprime[4295098369]
1

That means also, my explanation above with int64 signed is wrong, because 4295098369 is not larger ...

hmmmmm, weird!
 
Last edited:
Specifically for 4295098369. If TCC only checked numbers less than SQRT(4295098369) = 65537, it would find no factors (because 65537 has no proper factors).
 
Yes, that would explain it!

Good we have THE expert here for math!
 
That means also, my explanation above with int64 signed is wrong, because 4295098369 is not larger ...

I'm pretty sure that yours is the correct explanation for the false negatives for numbers above 2^63. TCC is interpreting them as negative numbers, and therefore not prime.
 
On an even more trivial note: @ISPRIME in older versions of TCC returned 1 for values of n=0 and n=1. Now it's returning 0. Why would Rex bother? Somebody must have complained.... And it wasn't me....

Someone more pedantic than me!
 
Back
Top