From: James on 2 Mar 2010 17:04 Same bigint arguments for python and perl, but different results. Why? $ python -c 'import sys;import string;A=string.atol(sys.argv[1]);B=string.atol(sys.argv[2]);print A/ B;print A%B' 1234123421349021473959009509174 1242143346469273498789234 993543 594467900074151457593112 $ perl -Mbigint -le '($a,$b)=@ARGV;print$a/$b;print$a%$b' 1234123421349021473959009509174 1242143346469273498789234 993543.478582365 5.94467900038225e+23 TIA JL
From: Stachu 'Dozzie' K. on 2 Mar 2010 17:43 On 2010-03-02, James <hslee911(a)yahoo.com> wrote: > Same bigint arguments for python and perl, but different results. Why? > > $ python -c 'import sys;import > string;A=string.atol(sys.argv[1]);B=string.atol(sys.argv[2]);print A/ > B;print A%B' 1234123421349021473959009509174 1242143346469273498789234 > 993543 > 594467900074151457593112 > > $ perl -Mbigint -le '($a,$b)=@ARGV;print$a/$b;print$a%$b' > 1234123421349021473959009509174 1242143346469273498789234 > 993543.478582365 > 5.94467900038225e+23 $a and $b are still strings, which are converted to ordinary integer, not biginteger. Try adding zero to one of arguments to convert it to bigint: #v+ [dozzie(a)rudolf dozzie]$ perl -Mbigint -le 'my ($a, $b) = @ARGV; $a += 0; print $a / $b; print $a % $b;' 1234123421349021473959009509174 1242143346469273498789234 993543 594467900074151457593112 [dozzie(a)rudolf dozzie]$ #v- -- Secunia non olet. Stanislaw Klekot
From: Owen on 4 Mar 2010 03:38 On Mar 3, 9:43 am, "Stachu 'Dozzie' K." <doz...(a)go.eat.some.screws.spammer.invalid> wrote: > On 2010-03-02, James <hslee...(a)yahoo.com> wrote: > > > Same bigint arguments for python and perl, but different results. Why? > > > $ python -c 'import sys;import > > string;A=string.atol(sys.argv[1]);B=string.atol(sys.argv[2]);print A/ > > B;print A%B' 1234123421349021473959009509174 1242143346469273498789234 > > 993543 > > 594467900074151457593112 > > > $ perl -Mbigint -le '($a,$b)=@ARGV;print$a/$b;print$a%$b' > > 1234123421349021473959009509174 1242143346469273498789234 > > 993543.478582365 > > 5.94467900038225e+23 > > $a and $b are still strings, which are converted to ordinary integer, > not biginteger. Try adding zero to one of arguments to convert it to > bigint: > > #v+ > [dozzie(a)rudolf dozzie]$ perl -Mbigint -le 'my ($a, $b) = @ARGV; $a += 0; print $a / $b; print $a % $b;' 1234123421349021473959009509174 1242143346469273498789234 > 993543 > 594467900074151457593112 > [dozzie(a)rudolf dozzie]$ > #v- > > -- > Secunia non olet. > Stanislaw Klekot Totally irrelevant, but as a matter of so called good practice, $a and $b should not be used as general variables in perl as they are special variables when using sort. FWIW, probably <$0.02 Owen
|
Pages: 1 Prev: Performance problem - Not able to write to file Next: Calculations in .csv via SED AWK |