in reply to Out of memory.
Hi, I don't think that there is a real out-of-memory problem, but surely a problem with accuracy. Sorry, I am too tired to decode your program right now, but it looks a little bit C-ish to me. Something more terse and Perlish to start from might be:
Seems that the equation is not complete? Furthermore, as you can see, the usual built-in precision might not be sufficient for your purpose. So you should have a look at e.g. Math::BigInt too.#!/usr/bin/perl use strict; chomp (my $equation = <DATA>); my @stack; foreach ( split(/\s*,\s*/, $equation) ) { push(@stack,$_), next if /\d+/; die "stack underrun" if @stack < 2; my ($val1, $val2) = (pop(@stack), pop(@stack)); push(@stack, $val1 + $val2), next if $_ eq '+'; push(@stack, $val1 * $val2), next if $_ eq 'x'; die "undef. operator ($_)"; } print "Result (stack): ", join(", ", @stack), "\n"; __DATA__ 1,2,3,4,+,5,+,x,6, ...... x,x,x,x,x,9164,x,+,9165,9166,91 <--- you +r input as a single line Result (stack): 1, 144, 1.9792773969506e+27, 6.22437334578068e+26, 5.7 +7209920038837e+273, 8966, 4.97957520221034e+261, 9165, 9166, 91
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Out of memory.
by dneedles (Sexton) on Oct 22, 2008 at 01:22 UTC | |
by Perlbotics (Archbishop) on Oct 22, 2008 at 10:51 UTC | |
by dneedles (Sexton) on Oct 25, 2008 at 21:46 UTC |