docster has asked for the wisdom of the Perl Monks concerning the following question:
I needed to write a generator for it in perl that could calculate this same number exactly, to run from a webserver. Well I figured this would be a simple task as perl is powerful. So I "ported" the calculations over to a perl script... but, they come out wrong! It seems that the perl script gains +1 each time through which I have narrowed down to seemingly it rounding off the number through each pass and slowly creeping or drifting off. Now it could be the opposite... maybe the windows app is drifting off. But the windows app has reliably reproduced the same 16 digit number on hundreds of machines and has been in use a good while so we need perl to match the output.
Basically it would work like this looping through and then format the number into a serial at the bottom.
Seed: blabla # would loop through 6 times. Once per character.my $seed = "$name$email$item"; while ($seed =~/(.)/g) { $n += 1; if (uc($1) eq uc('a')) { $i = ($i + 173); } # many many lines and calulations here } my $m=sprintf("%.f",$i) ; my $trimmedNumber = substr($m, -16, 16); # trim 16 from the right. printf ("Trimmed: $trimmedNumber\n");
Windows app: 2500202166709743
Perl app: 2500202166709760
There are a lot of things here. One was written and run on windows with c++, the other is written and run on linux in perl. The c++ cannot be changed as it has been in use a good while. Can I make perl cooperate or should I just stop now?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: The 16 digit number dilemma.
by swampyankee (Parson) on Feb 06, 2006 at 17:50 UTC | |
by docster (Novice) on Feb 06, 2006 at 19:42 UTC | |
by GrandFather (Saint) on Feb 06, 2006 at 19:54 UTC | |
by docster (Novice) on Feb 06, 2006 at 20:11 UTC | |
by GrandFather (Saint) on Feb 06, 2006 at 20:21 UTC | |
| |
|
Re: The 16 digit number dilemma.
by Fletch (Bishop) on Feb 06, 2006 at 18:31 UTC | |
|
Re: The 16 digit number dilemma.
by japhy (Canon) on Feb 06, 2006 at 17:56 UTC | |
|
Re: The 16 digit number dilemma.
by BrowserUk (Patriarch) on Feb 06, 2006 at 18:29 UTC | |
|
Re: The 16 digit number dilemma.
by DrHyde (Prior) on Feb 07, 2006 at 10:11 UTC |