Jump to content

[SOLVED] Multiplying stupid numbers...


keiran420

Recommended Posts

It's quite old, so I bet it's written in C, but yeah....

 

 

It doesn't perform so much more quickly because it's written in C (or C++ or what ever) (although that does help).  My guess would be it's so much quicker because of how it operates on the strings.  It probably doesn't slice and dice.

Link to comment
Share on other sites

Just a quick one guys.

 

My code is about at what it was, got an idear on how to add decimal points...

 

But 1st, theres a kind of bug....

 

When i run my code, it will only really return a result around 9 out of 10 times... that 1 out of 10, it simply returns nothing, regardless of the size or complexity of the numbers....

 

Why is this?

Link to comment
Share on other sites

I gather no error messages are displayed?

 

Try to find out, what input numbers are causing it.

 

No, i cant get an error..

 

It will do it with any number...

 

I could multiply the same numbers 10 times in a row, it could fail the 11th...

it could fail for the 1st 10, then work on the 11th, its random...

 

Also note, that when it does this for larger numbers, the blankness is returned instantly... so it must be somthing near the top... no?

 

I wass thinking maybe str_spli doesnt like splitting 2x 5000 long strings... but it does it on 2x 5 digi strings aswell...

 

Ill try harder to squeeze an error out of it somewhere....

Link to comment
Share on other sites

Random behaviour is a bad sign... :(

 

Indeed...

I have tried my best at error messages, though i just cant seem to get any reason.

 

Here is the exact code im running...

Function Mul($numbera, $numberb){
  $number1=Str_split($numbera); $number2=Str_split($numberb);
  Foreach ($number2 As $b){ ++$down; $across=-1;
    Foreach ($number1 As $a){ ++$across;
       $muls[$down+$across]+=$a*$b;
    }
  }
  $muls=Array_reverse($muls);
  Foreach ($muls As $mul){ ++$counter;
     $add=$mul+$carry;
    If ($add>9){$total[$counter] = $add % 10;
                $carry = $add/10 - $total[$counter]/10;}
    Else{     $total[$counter] = $add;
                $carry  = 0;}
  }
  Array_push($total,$carry); $total=Array_reverse($total);
  $total=Implode($total); $total=Ltrim($total,"0"); Return $total;
}

 

And i was calling it with

 

$c="1234567890";
$b="0987654321";
Echo Mul($c,$b);

 

Again, the majority of the time it returns the correct answer 1219326311126352690, but just not every time... >.<

 

No good if i ever wanted to use this function fo real... would have to check if it worked every time i used it!

 

Link to comment
Share on other sites

Oh, got some.... i newish to errors, just been on w3schools...

 

 

Notice: Undefined variable: down in

C:\Users\keiran\Documents\php7CC7.tmp on line 14 Notice: Undefined offset: 1 in C:\Users\keiran\Documents\php7CC7.tmp on line 16 Notice: Undefined offset: 2 in C:\Users\keiran\Documents\php7CC7.tmp on line 16 Notice: Undefined offset: 3 in C:\Users\keiran\Documents\php7CC7.tmp on line 16 Notice: Undefined offset: 4 in C:\Users\keiran\Documents\php7CC7.tmp on line 16 Notice: Undefined offset: 5 in C:\Users\keiran\Documents\php7CC7.tmp on line 16 Notice: Undefined offset: 6 in C:\Users\keiran\Documents\php7CC7.tmp on line 16 Notice: Undefined offset: 7 in C:\Users\keiran\Documents\php7CC7.tmp on line 16 Notice: Undefined offset: 8 in C:\Users\keiran\Documents\php7CC7.tmp on line 16 Notice: Undefined offset: 9 in C:\Users\keiran\Documents\php7CC7.tmp on line 16 Notice: Undefined offset: 10 in C:\Users\keiran\Documents\php7CC7.tmp on line 16 Notice: Undefined variable: counter in C:\Users\keiran\Documents\php7CC7.tmp on line 20 Notice: Undefined variable: carry in C:\Users\keiran\Documents\php7CC7.tmp on line 21 2339716752

 

Though thats the right answer...

 

but that looks bad...

Link to comment
Share on other sites

Nah... these aren't really serious.

"Undefined offset: 1" means, that there's an array variable $foo, where $foo[1] is not set.

 

"Undefined variable: counter" means, that you didn't assign any value to $counter before using it.

Link to comment
Share on other sites

Nah... these aren't really serious.

"Undefined offset: 1" means, that there's an array variable $foo, where $foo[1] is not set.

 

"Undefined variable: counter" means, that you didn't assign any value to $counter before using it.

 

and after 25 refresh's of it working with the errors, i gets another 100% blank page...

Link to comment
Share on other sites

Ok... can you get access to CGI logs? It seems that PHP or Apache crashes from time to time

 

This is probibly all it is, im actually running my script from "PHP Expert Editor"...

 

I found an application with cgi in its name, but i cant find any cgi logs savrd anywhere...

Link to comment
Share on other sites

They would usually be in folder called 'logs' somewhere. You might want to try to find one.

Usual names are apache_error.log and php_error.log

 

Searched my c drive, and nope.

 

no lof folder, or php_error.log

 

dont have apache, just some php editor/runner and php/mysql

Link to comment
Share on other sites

So maybe install one :P

 

Try WampServer

At least I will be able to tell you exactly where the log files are ;)

(this contains Apache, MySQL and PHP so you might need to uninstall your current versions)

 

;)

 

You can of course configure php logging in php.ini :)

Link to comment
Share on other sites

So maybe install one :P

 

Try WampServer

At least I will be able to tell you exactly where the log files are ;)

(this contains Apache, MySQL and PHP so you might need to uninstall your current versions)

 

;)

 

You can of course configure php logging in php.ini :)

 

Ok, i have downloaded it, but i casnt seem to run .php files....

 

this is the error log...

 

[06-Dec-2008 18:46:54] PHP Notice:  Undefined variable: mywampfp in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:46:54] PHP Notice:  Undefined variable: i in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:46:54] PHP Notice:  Undefined variable: mywampini in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:46:54] PHP Notice:  Undefined offset:  1 in C:\wamp\scripts\refresh.php on line 385

[06-Dec-2008 18:46:54] PHP Notice:  Undefined offset:  1 in C:\wamp\scripts\refresh.php on line 385

[06-Dec-2008 18:47:03] PHP Notice:  Undefined variable: mywampfp in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:47:03] PHP Notice:  Undefined variable: i in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:47:03] PHP Notice:  Undefined variable: mywampini in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:47:03] PHP Notice:  Undefined offset:  1 in C:\wamp\scripts\refresh.php on line 385

[06-Dec-2008 18:47:03] PHP Notice:  Undefined offset:  1 in C:\wamp\scripts\refresh.php on line 385

[06-Dec-2008 18:47:15] PHP Notice:  Undefined variable: mywampfp in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:47:15] PHP Notice:  Undefined variable: i in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:47:15] PHP Notice:  Undefined variable: mywampini in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:47:15] PHP Notice:  Undefined offset:  1 in C:\wamp\scripts\refresh.php on line 385

[06-Dec-2008 18:47:15] PHP Notice:  Undefined offset:  1 in C:\wamp\scripts\refresh.php on line 385

[06-Dec-2008 18:47:50] PHP Notice:  Undefined variable: mywampfp in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:47:50] PHP Notice:  Undefined variable: i in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:47:50] PHP Notice:  Undefined variable: mywampini in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:47:50] PHP Notice:  Undefined offset:  1 in C:\wamp\scripts\refresh.php on line 385

[06-Dec-2008 18:47:50] PHP Notice:  Undefined offset:  1 in C:\wamp\scripts\refresh.php on line 385

[06-Dec-2008 18:50:56] PHP Notice:  Undefined variable: mywampfp in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:50:56] PHP Notice:  Undefined variable: i in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:50:56] PHP Notice:  Undefined variable: mywampini in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:50:56] PHP Notice:  Undefined offset:  1 in C:\wamp\scripts\refresh.php on line 385

[06-Dec-2008 18:50:56] PHP Notice:  Undefined offset:  1 in C:\wamp\scripts\refresh.php on line 385

[06-Dec-2008 18:51:35] PHP Notice:  Undefined variable: mywampfp in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:51:35] PHP Notice:  Undefined variable: i in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:51:35] PHP Notice:  Undefined variable: mywampini in C:\wamp\scripts\refresh.php on line 252

[06-Dec-2008 18:51:35] PHP Notice:  Undefined offset:  1 in C:\wamp\scripts\refresh.php on line 385

[06-Dec-2008 18:51:35] PHP Notice:  Undefined offset:  1 in C:\wamp\scripts\refresh.php on line 385

Link to comment
Share on other sites

What are the lines that correspond to those notices?  (And the lines surrounding those lines.)

 

I just tried to run a hello world script in the 'www' file...

 

Also clicked on one of the standard php files in on of the other files...

 

And this stuff appeared in my log...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.