factorial of negative one (-1)

Chris Rebert clp2 at rebertia.com
Mon Nov 1 09:36:32 CET 2010


> On Mon, Nov 1, 2010 at 4:19 AM, Bj Raz <whitequill.bj at gmail.com> wrote:
>> On Fri, Oct 29, 2010 at 1:02 AM, Chris Rebert <clp2 at rebertia.com> wrote:
>>> On Thu, Oct 28, 2010 at 9:41 PM, Bj Raz <whitequill.bj at gmail.com> wrote:
>>> > I am working with differential equations of the higher roots of
>>> > negative
>>> > one. (dividing enormous numbers into other enormous numbers to come out
>>> > with
>>> > very reasonable numbers).
>>> > I am mixing this in to a script for Maya (the final output is
>>> > graph-able as
>>> > a spiral.)
>>> > I have heard that Sage, would be a good program to do this in, but I'd
>>> > like
>>> > to try and get this to work in native python if I can.
>>> > The script I am trying to port to Python
>>> > is; http://pastebin.com/sc1jW1n4.
>>>
>>> Unless your code is really long, just include it in the message in the
>>> future.
>>> So, for the archive:
>>> indvar = 200;
>>> q = 0;
>>> lnanswer = 0;
>>> for m = 1:150
>>>  lnanswer = (3 * m) * log(indvar) - log(factorial(3 * m))  ;
>>> q(m+1) = q(m)+ ((-1)^m) * exp(lnanswer);
>>> end
>>> lnanswer
>>> q
On Mon, Nov 1, 2010 at 1:23 AM, Bj Raz <whitequill.bj at gmail.com> wrote:
> Simply out of curiosity is there a way to force python to print more then 16
> places from the decimal? For better accuracy.

(1) Please don't top-post. (http://en.wikipedia.org/wiki/Top-post )
(2) The underlying double-precision floating-point number only has ~16
decimal digits of precision, so it's pointless to print out "further"
digits.
(3) If you actually need more than 16 decimal places, use something
like the `decimal.Decimal` datatype:
http://docs.python.org/library/decimal.html

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list