corbin Posted December 4, 2008 Share Posted December 4, 2008 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. Quote Link to comment Share on other sites More sharing options...
keiran420 Posted December 6, 2008 Author Share Posted December 6, 2008 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? Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 I gather no error messages are displayed? Try to find out, what input numbers are causing it. Quote Link to comment Share on other sites More sharing options...
keiran420 Posted December 6, 2008 Author Share Posted December 6, 2008 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.... Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 Random behaviour is a bad sign... Quote Link to comment Share on other sites More sharing options...
keiran420 Posted December 6, 2008 Author Share Posted December 6, 2008 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! Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 Try adding some debugging code. I mean: echo some variables (or save to file so that's easier to analyze) within function, to see if they don't get strange values. Quote Link to comment Share on other sites More sharing options...
keiran420 Posted December 6, 2008 Author Share Posted December 6, 2008 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... Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 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. Quote Link to comment Share on other sites More sharing options...
keiran420 Posted December 6, 2008 Author Share Posted December 6, 2008 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... Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 Ok... can you get access to CGI logs? It seems that PHP or Apache crashes from time to time Quote Link to comment Share on other sites More sharing options...
keiran420 Posted December 6, 2008 Author Share Posted December 6, 2008 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... Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 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 Quote Link to comment Share on other sites More sharing options...
keiran420 Posted December 6, 2008 Author Share Posted December 6, 2008 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 Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 So maybe install one 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 Quote Link to comment Share on other sites More sharing options...
keiran420 Posted December 6, 2008 Author Share Posted December 6, 2008 So maybe install one 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 Quote Link to comment Share on other sites More sharing options...
corbin Posted December 6, 2008 Share Posted December 6, 2008 What are the lines that correspond to those notices? (And the lines surrounding those lines.) Quote Link to comment Share on other sites More sharing options...
keiran420 Posted December 6, 2008 Author Share Posted December 6, 2008 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... Quote Link to comment Share on other sites More sharing options...
keiran420 Posted December 7, 2008 Author Share Posted December 7, 2008 Got wampserver working, and it compiled and ran 100/100 trial runs... Seems to have done it... Thanks dudes ^^ Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 7, 2008 Share Posted December 7, 2008 Try it also on some online host. The more it's tested, the better Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.