Squeak 4.5 error: #isPrime fails with relatively small Mersenne prime

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Squeak 4.5 error: #isPrime fails with relatively small Mersenne prime

LawsonEnglish
This bit of code fails at numb := 1024:

error: Cannot truncate this number

numb := 1024.
1 to: numb do: [:n||test| test:=(2 raisedTo: n) -1. (test isPrime)
ifTrue: [Transcript show: n; tab; show: test;cr]]

#isProbablyPrime fails with the same number.


numb := 1023.
works for both.





L

--
Squeak from the very start (introduction to Squeak and Pharo Smalltalk for the (almost) complete and compleate beginner).
https://www.youtube.com/playlist?list=PL6601A198DF14788D&feature=view_all

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan


Reply | Threaded
Open this post in threaded view
|

Re: Squeak 4.5 error: #isPrime fails with relatively small Mersenne prime

David T. Lewis
On Tue, Feb 10, 2015 at 02:39:19AM -0700, Lawson English wrote:

> This bit of code fails at numb := 1024:
>
> error: Cannot truncate this number
>
> numb := 1024.
> 1 to: numb do: [:n||test| test:=(2 raisedTo: n) -1. (test isPrime)
> ifTrue: [Transcript show: n; tab; show: test;cr]]
>
> #isProbablyPrime fails with the same number.
>
>
> numb := 1023.
> works for both.
>

It looks like a problem in random number generation. It is failing in
LargePositiveInteger>>atRandom which somehow results in the random
generator producing a value of Float infinity.

Dave


Reply | Threaded
Open this post in threaded view
|

Re: Squeak 4.5 error: #isPrime fails with relatively small Mersenne prime

Bert Freudenberg
On 10.02.2015, at 13:39, David T. Lewis <[hidden email]> wrote:

>
> On Tue, Feb 10, 2015 at 02:39:19AM -0700, Lawson English wrote:
>> This bit of code fails at numb := 1024:
>>
>> error: Cannot truncate this number
>>
>> numb := 1024.
>> 1 to: numb do: [:n||test| test:=(2 raisedTo: n) -1. (test isPrime)
>> ifTrue: [Transcript show: n; tab; show: test;cr]]
>>
>> #isProbablyPrime fails with the same number.
>>
>>
>> numb := 1023.
>> works for both.
>>
>
> It looks like a problem in random number generation. It is failing in
> LargePositiveInteger>>atRandom which somehow results in the random
> generator producing a value of Float infinity.
>
> Dave
Yep. Random>>nextInt: does not work for really large ints. Fixed in Kernel-bf.899.

- Bert -






smime.p7s (5K) Download Attachment