Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

perl

Name: Anonymous 2010-07-12 20:20

I first asked /sci/ but now I'm on the right board. I'm having some issues with a program I'm writing in perl.
The program starts with the string "9" and mod's it by a prime.
If the result is > 0 then it concatenates another 9 to the string and continues until the result is equal to 0.
It works fine until the number has 16 digits: 9999999999999999 % 17 = 1 for example. It appears the result after mod is always 1 higher than it should be when the number has more than 15 digits, regardless of the prime used.

I tried using bigint/bignum libraries but to no avail. Any ideas?

Thanks in advance.

Name: Anonymous 2010-07-12 20:24

Don't do it with a string, silly! Do it with a number.

Name: Anonymous 2010-07-12 20:26

Why would that cause a problem only after the length has reached 16?

Name: Anonymous 2010-07-12 20:29

I've just tried typecasting before doing the operation; as I expected, it didn't work (perl automatically decides what data type upon doing the operation)

Name: Anonymous 2010-07-12 20:30

print "99999999999999999" % 17 . "\n";
use bignum;
print "99999999999999999" % 17 . "\n";
10
9

Name: Anonymous 2010-07-12 20:34

I've already tried using bignum/bigint

Name: Anonymous 2010-07-12 20:35

>>6
the result after mod is always 1 higher than it should be
10
9


use bignum

Name: Anonymous 2010-07-12 20:49

>>7
use MY ANUS;

Name: Anonymous 2010-07-12 20:52

If I'm getting the primes out of a file, would that affect it? I tried using chomp. bignum doesn't work.

Name: Anonymous 2010-07-12 21:50

>>9
I'm not sure you understand. Bignum does work.
Don't blame your inadequacies on your tools.

Name: Anonymous 2010-07-12 22:15

>>9
Look, the guys here are going to be dicks to you without explaining why until you post your source (use code tags!)

Perl is known for being just a hair more batshit insane when it comes to numbers than you would expect. That said, bignum should work... and if it doesn't then it's probably something you implied while DWIMing something

Name: Anonymous 2011-02-03 5:56


Don't change these.
Name: Email:
Entire Thread Thread List