[gambit-list] Crash with newly found largest prime number
Marc Feeley
feeley at iro.umontreal.ca
Mon Jan 25 08:41:37 EST 2016
That is amusing! When you compile this program the compiler sees that the expression in calculate-largest-prime is a constant, so it computes the value at compilation time and dumps the value in the generated C code. If you are patient, add the -expansion option to see the code after the high level program transformations. You will see:
(define calculate-largest-prime
(lambda ()
3003764…))) ;; over 22 million digits!
So the (time (calculate-largest-prime)) reports a run time of 0 milliseconds!
Anyway, the segfault happens in number->string . I don’t yet know why but I suspect a bug in gcc due to the enormous bignum constant. I’ll investigate.
Marc
> On Jan 25, 2016, at 3:58 AM, Alex Silva <asandroq at gmail.com> wrote:
>
> Hallo,
>
> The following program works fine when interpreted, but crashes when
> compiled:
>
> ```
> (declare
> (block)
> (standard-bindings)
> (extended-bindings))
>
> (define (calculate-largest-prime)
> (- (expt 2 74207281) 1))
>
> (define *largest-prime* (time (calculate-largest-prime)))
> (define *prime-string* (time (number->string *largest-prime*)))
> (time (println *prime-string*))
> ```
>
> Gambit 4.8.3, GCC 5.3.0, Ubuntu 14.04
>
> --
> -alex
> http://unendli.ch/
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
More information about the Gambit-list
mailing list