Is it the intended operation of the 'factorial' program on the Parrot examples page to truncate the results? Looks like a bug to me...
James Ghofulpo
General Electric Transportation Systems
2901 East Lake Road 63-2E, Erie, PA 16531
Tel: +1-814-875-5747 Fax: +1-201-477-6930
NOTICE: The information contained in this email and any document attached hereto is intended only for the named recipient(s). It is the property of the General Electric Company and shall not be used, disclosed or reproduced without the express written consent of the General Electric Company. If you are not the intended recipient (or the employee or agent responsible for delivering this message in confidence to the intended recipient(s)), you are hereby notified that you have received this transmittal in error, and any review, dissemination, distribution or copying of this transmittal or its attachments is strictly prohibited. If you have received this transmittal and/or attachments in error, please notify me immediately by reply email or telephone 814-875-5747 and immediately delete this message and all its attachments. Thank you.
> Is it the intended operation of the 'factorial' program on the Parrot
> examples page to
> truncate the results? Looks like a bug to me...
I have checked the factorial example on
http://www.parrotcode.org/examples/pasm.html.
Starting with 13! incorrect results are indeed returned on my 32bit
Linux machine.
Should there a promotion to BigInt be taking place? on an overflow
indication?
--
/* Bernhard.S...@gmx.de */
Most of the examples are really old and partially outdated. I think there
should be very few PASM examples, more complex examples should be in
PIR. Regarding the factorial: using .Integer PMCs would fix it.
leo
The first 15 factorials are:
1
2
6
24
120
720
5040
40320
362880
3628800
39916800
479001600
no bigint lib loaded
current instr.: '(null)' pc 16 ((unknown file):-1)
To address the other point, I'll reorganize the examples in the next
few days to reduce the size of the PASM and split up the PIR into
multiple pages.
I'm not surprised, the values listed on that webpage for !13, !14 and
!15 are wrong.
According to my lisp interpreter the correct values (Google confirmed)
are:
13! = 6227020800
14! = 87178291200
15! = 1307674368000
In case someone should be really bored, here's a link to more then you
ever wanted to know about factorials:
http://mathworld.wolfram.com/Factorial.html
Cheers,
-J
--
>I'm not surprised, the values listed on that webpage for !13, !14 and
>!15 are wrong.
>
>According to my lisp interpreter the correct values (Google confirmed)
>are:
>
> 13! = 6227020800
> 14! = 87178291200
> 15! = 1307674368000
>
>
Well, the problem is that Parrot indeed returns the incorrect values
that are
mentioned in the webpage.
CU, Bernhard
I happen to get the correct answers out to 20! but only because I'm on
64bit hardware. The real issue is that the C standards specifies integer
overflow as undefined behavior. Supposedly, with the proper flags, you
can get gcc to give you a SIGFPE on signed overflow. AFAIK - there is
no portable way to trap the overflow. I think the best we can hope for
is automatic promotion of literals by the compiler/assembler.
-J
--
--
On Sun, Sep 11, 2005 at 01:06:57PM +0200, Bernhard Schmalhofer wrote:
> Well, the problem is that Parrot indeed returns the incorrect values
> that are
> mentioned in the webpage.
I'd like to propose that we fix the n! values listed on the examples page,
change the code example to the snippet below, and add a warning about BigInt's
requiring that GMP is installed.
--
print "The first 30 factorials are:\n"
set I1, 0
set I2, 30
new P0, .BigInt
set P0, 1
REDO: inc I1
mul P0, P0, I1
print P0
print "\n"
lt I1, I2, REDO
DONE: end
--
Cheers,
-J
--
>I'd like to propose that we fix the n! values listed on the examples page,
>change the code example to the snippet below, and add a warning about BigInt's
>requiring that GMP is installed.
>
>
Hi,
I have added information on how to provide patches to
http://www.parrotcode.org
to docs/submissions.pod.
Basically you create patches against
https://*svn*.perl.org/perl.org/docs/live/*parrotcode*/
<http://www.google.com/url?sa=D&q=https://svn.perl.org/perl.org/docs/live/parrotcode/>
(guest/guest)
and send them to webmaster at perl.org.
CU, Bernhard
The guest account doesn't seem to be working from either subversion or my
web browser.
--
$ svn co --username guest --password guest https://svn.perl.org/perl.org/docs/live/parrotcode/
Authentication realm: <https://svn.perl.org:443> perl.org
Username: guest
Password for 'guest':
Authentication realm: <https://svn.perl.org:443> perl.org
Username: guest
Password for 'guest':
svn: PROPFIND request failed on '/perl.org/docs/live/parrotcode'
svn: PROPFIND of '/perl.org/docs/live/parrotcode': authorization failed (https://svn.perl.org)
--
Cheers,
-J
--
-J
--
> What happened to the factorial PASM example? It seems to have
> disappeared and it hasn't re-appeared as a PIR example either.
It used bogus high numbers beyond int32 range and was just broken.
leo
Only because it was using integer registers. Limiting it to low
factorial values or using Integer pmcs would resolve the issue. I'm
going to add a PIR example using Integer pmcs unless there are any
objections.
-J
--
Did you add the examples? I'd like to close the ticket.
Allison
The examples aren't on the website, but examples/pasm/fact.pasm is fixed
as of r26432.