Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

A PHP function i made...

  • Please log in to reply



    New Member

  • Member
  • Pip
  • 2 posts
Hey dudes/geeks :)

I'm new here, just browsed the web for somewhere to get a few opinions on a php functions i have been making.

Cant really see a programming or php forum here, and i like offtopic, so here it is.

Nothing to special, lol, im no expert, but i like how i have used arrays and maths in it...

Its basically just a multiplyer for 2 numbers, sorry no decimals, yet(maybe advice how).

I have had it square a 100,000 didgit long number so far...

And its fairly quick on around a 5,000 digit * 5,000 digit number.

I just wanted opinons on how efficiant the code is, maybe somthing im doing thats unneeded, or to long.
Basically anything to help it go that extra inch...

Heres my coding progress...
//takes the input of 2 numbers
function mul($numbera, $numberb){
//and splits each to an array
//we have a nested loop that grabs each digit, and multiplys
//it with every other diget of the other number...
//these results are then added to a new array
   foreach ($number2 as $b){ ++$down; $across=-1;
	  foreach ($number1 as $a){ ++$across;
//sexy sexy line of code ^^
//we flip the numbers in reverse and work through them 1 by 1
   foreach ($muls as $mul){ ++$counter;
//$add is the total of the number and carryover
//if its more than 9, (2 digits or more long)
	  if ($add>9){
//total is the last digit of the number
//carry are all the digits that where before it
//else total IS add, and no carry
//add on any straggling carry over
//reverse it once more
//implode to a string
//and trim of any junk 0's
   return $total;

I think i have gotten it to an error free stage, please tell if you find any buggy numbers...

I think it might be usefull becuase it can instantly multiply numbers far bigger than what '*' or any other STANDARD php function can can do.

Even if it does take its sweet [bleep] time if you chuck it 2 100,000 digit long beasts....

Anyway, what do you guys think? :)
  • 0




    Member 5k

  • Retired Staff
  • 21,285 posts
  • MVP
Moved to the web development forum.
  • 0

Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP