4

My application (PHP) requires to perform lot of high precision mathematics (A total of 100 digits may even occur)

Through last couple of posts in this forum, I could figure out that I have to use any high precision libraries like BC Math or GMP because the float type can not deal with lengthy data as their max size is limited

Since my application requires decimals number and GMP do not support decimals, the choice is obvious that to go with BC Math

I am just trying to figure out the best approach now in terms of performance

Case 1 : Check the numbers before any mathematical operation Perform calculations in the usual way if the result exceeds the floating limit, perform BC Math operations and get accurate result

Case 2 : Directly use BC Math from the begining

Assume that 50% of calculations does not need high precision mathematics. In this case, which one will be better in terms of performance

Suggestions please

2
  • I also want to know..:) Commented Sep 29, 2013 at 16:57
  • Any documentation is available to understand how slow BC Math is when compared to the native processing? I have tested locally and time difference is negligible. Commented Sep 29, 2013 at 17:07

1 Answer 1

0

I used WolframAlpha to calculate some math problems which is hard to PHP. Therefore WolframAlpha is speedy from our computers and if you have an internet connection , you can use it. It's the example for calculate root of largest numbers. And the result is awfull , check it.

<?php function pow_a($a,$b){ $a = file_get_contents("http://www.wolframalpha.com/input/?i=$a"."%5E"."$b"); if(preg_match_all('/first\sbtn\"\>\<a\shref\=\"(.*?)\"/', $a, $m)) $b = file_get_contents("http://www.wolframalpha.com/input/".htmlspecialchars_decode($m[1][0])); if(preg_match_all("/\"stringified\"\:\s\"(.*?)\.\.\./i", $b, $k)) return $k[1][0]; } echo pow_a("9999999999999999999999999", "0.2222"); ?> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.