{"id":63696,"date":"2024-05-24T03:01:39","date_gmt":"2024-05-23T17:01:39","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=63696"},"modified":"2024-05-24T18:49:35","modified_gmt":"2024-05-24T08:49:35","slug":"php-bcmath-factorial-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-bcmath-factorial-tutorial\/","title":{"rendered":"PHP Bcmath Factorial Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/use_bcmath.php\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"PHP Bcmath Factorial Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/use_bcmath.gif\" title=\"PHP Bcmath Factorial Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP Bcmath Factorial Tutorial<\/p><\/div>\n<p>Today we&#8217;ve had great guidance from <a target=_blank title='Useful link, thanks' href='https:\/\/www.php.net\/manual\/en\/book.bc.php'>this webpage&#8217;s contributors<\/a>, thanks, writing a Factorial Calculator, using PHP and its <a target=_blank title='PHP Bcmath extension information' href='https:\/\/www.php.net\/manual\/en\/book.bc.php#:~:text=BCMath%20Arbitrary%20Precision%20Mathematics%20%C2%B6&#038;text=This%20extension%20is%20an%20interface,Philip%20Nelson%3B%20hence%20the%20name.'>Bcmath<\/a> extension, revisiting concepts we last talked about when we presented <a title='PHP Bcmath Primer Tutorial' href='#phpbpt'>PHP Bcmath Primer Tutorial<\/a>.<\/p>\n<p>Are you like me with maps and sometimes with long numbers &#8230; just staring at a long integer trying to find patterns?<\/p>\n<p>Well, you need to let &#8230;<\/p>\n<blockquote style=font-size:44px;><p>\n<a target=_blank style='cursor:pointer;text-decoration:none;' href='https:\/\/en.wikipedia.org\/wiki\/Factorial'>Factorials<\/a>\n<\/p><\/blockquote>\n<p> &#8230; into your life &#8230; the bigger the better!   Wonder at all those zeroes at the end?  Carve a long factorial into a piece of soap?  <a target=_blank title='?' href='https:\/\/www.youtube.com\/watch?v=-kbTbg00AJU'>They<\/a> say the Lord&#8217;s Prayer was written on a pinhead &#8230; what are you waiting for?!<\/p>\n<p>Or just avail yourself of today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/use_bcmath.php_GETME\">use_bcmath.php<\/a> first draft PHP <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/use_bcmath.php\">Factorial Calculator<\/a> &#8230;<\/p>\n<p><iframe src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/use_bcmath.php\" style=\"width:90%;height:700px;\"><\/iframe><\/p>\n<p> &#8230; therapy.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/php-bcmath-factorial-tutorial\/'>PHP Bcmath Factorial Tutorial<\/a>.<\/p-->\n<hr>\n<p id='phpbpt'>Previous relevant <a target=_blank title='PHP Bcmath Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php-bcmath-primer-tutorial\/'>PHP Bcmath Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/got_big_numbers.php\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"PHP Bcmath Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/bcmath.jpg\" title=\"PHP Bcmath Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP Bcmath Primer Tutorial<\/p><\/div>\n<p>Today we have an unusual linkage of tutorials, where we link our tutorial here, today, called &#8220;PHP Bcmath Primer Tutorial&#8221; with one from some time back (and I.T. historically speaking, a really long way back) called <a target=_blank title='Lisp Primer Tutorial' href='#lpt'>Lisp Primer Tutorial<a> as shown below.<\/p>\n<p>The link is the way the languages handle some arithmetic on very large numbers, and today we present a web application that is like a calculator for some of those very large number calculations.  Am not certain Lisp does the work this way, but the <a target=_blank href='http:\/\/php.net\/manual\/en\/ref.bc.php' title='PHP bcmath information'>&#8220;bcmath&#8221;<\/a> module in PHP, that we use for the purpose here today, uses &#8220;strings&#8221; to achieve the affect, so that I don&#8217;t believe there are any times during the calculations, necessarily, with the CPU <a target=_blank title='Register information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Processor_register'>register<\/a>, that there are any great huge numbers being handled, but piece by piece, the CPU register is helping piece together that string that represents the answer we are after, not using any scientific notation in the process.<\/p>\n<p>We throw into the mix a bit of fun and games &#8230; just imagine you are on Central (train) Station in Sydney, or loads of other train stations in the world where it is pretty obvious the station announcements are pieced together bits of audio, and today we make use of the wonderful <a target=_blank title='Google Translate' href='http:\/\/translate.google.com'>Google Translate<\/a> functionality in order for you to, optionally (and not always &#8230; no go with Firefox for instance), hear the results in those great mellifluous tones (in English, as default).<\/p>\n<p>Hope you really give some curly questions out there to the <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/got_big_numbers.php\" title='Click picture'>live run<\/a>.  Here is the PHP source code using the &#8220;bcmath&#8221; module you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/got_big_numbers.php_GETME\" title=\"got_big_numbers.php\">got_big_numbers.php<\/a><\/p>\n<hr>\n<p id='lpt'>Previous relevant <a target=_blank title='Lisp Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/lisp-primer-tutorial\/'>Lisp Primer Tutorial<a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Lisp\/\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Lisp Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Lisp\/Lisp_Primer.jpg\" title=\"Lisp Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Lisp Primer Tutorial<\/p><\/div>\n<p>Have you heard of Lisp, the programming language?  Do you remember how incredible Hewlett Packard calculators were back in the 1970&#8217;s (we did as Land Surveyors &#8230; they were the bee&#8217;s knees, especially to program for those Land Surveying calculations).   And do you (older users) remember the excitement regarding reverse Polish notation?  Well, Lisp, the second oldest high-level language (after Fortran) uses this reverse Polish notation and thinking.<\/p>\n<p>Am no expert with Lisp, as you&#8217;ll see, and we&#8217;ll defer to code available on the net and contributed by others, but have to mention its incredible mathematical scope, for instance, with its functionality for huge numbers (integers).   You will notice with languages like C++ it is not at all easy doing a calculation like the factorial of 1000 &#8230; or 1000! &#8230; or 1000 x 999 x 998 x &#8212;&gt; x 2 x 1 &#8230; but Lisp does it with considerable ease.   As a matter of interest, as far as this type of big integer in Java, you may want to check on the <a target=_blank title='Good link ... thanks ... with advice about Java BigO data type' href='http:\/\/stackoverflow.com\/questions\/17118210\/big-o-simple-explaining-and-use-in-java'>BigO data type<\/a>.<\/p>\n<p>Today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Lisp\/\" title='Click picture.'>tutorial<\/a> introduces you to Lisp we install using LispWorks Personal on a Mac laptop, and execute a Hello World and some large factorial calculations.   Lisp, being the old language it is, is a very functional language, and although global variables are allowed, the Lisp &#8220;way&#8221; is not to resort to such approaches.<\/p>\n<p>Below are some links regarding Lisp you may want to peruse:<\/p>\n<ul>\n<li><a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/Lisp_%28programming_language%29' title='Lisp information from Wikipedia'>Lisp<\/a> information from Wikipedia<\/li>\n<li><a target=_blank href='http:\/\/www.lispworks.com\/downloads\/index.html' title='Download website for Mac'>LispWorks Personal Edition<\/a> for MacBook Pro<\/li>\n<li><a target=_blank href='http:\/\/cs.gmu.edu\/~sean\/lisp\/LispTutorial.html' title='Lisp Quickstart'>Lisp Quickstart<\/a> where factorial code is from &#8230; thanks<\/li>\n<li><a target=_blank href='http:\/\/www.cs.sfu.ca\/CourseCentral\/310\/pwfong\/Lisp\/1\/tutorial1.html' title='Basic Lisp Programming Tutorial'>Basic Lisp Programming Tutorial<\/a><\/li>\n<li><a target=_blank href='http:\/\/www.chemie.fu-berlin.de\/chemnet\/use\/info\/elisp\/elisp_19.html' title='Interactive entry in Lisp'>Interactive entry in Lisp<\/a><\/li>\n<\/ul>\n<p>Will leave you with some downloadable programming Lisp source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Lisp\/helloworld.lisp_GETME\" title='helloworld.lisp'>helloworld.lisp<\/a> and some factorial code called <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Lisp\/factorial.lisp_GETME\" title='factorial.lisp'>factorial.lisp<\/a><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d7468' onclick='var dv=document.getElementById(\"d7468\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/?tag=Fortran\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d7468' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d14897' onclick='var dv=document.getElementById(\"d14897\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/?tag=PHP\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d14897' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d63696' onclick='var dv=document.getElementById(\"d63696\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/factorial\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d63696' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today we&#8217;ve had great guidance from this webpage&#8217;s contributors, thanks, writing a Factorial Calculator, using PHP and its Bcmath extension, revisiting concepts we last talked about when we presented PHP Bcmath Primer Tutorial. Are you like me with maps and &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-bcmath-factorial-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[1556,1797,411,452,2991,752,3004,2394,1520,932,4762,997,1262,1675,1319],"class_list":["post-63696","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-bcmath","tag-extension","tag-factorial","tag-form","tag-integer","tag-mathematics","tag-maths","tag-number","tag-numerical","tag-php","tag-php-extension","tag-programming","tag-textarea","tag-textbox","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/63696"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=63696"}],"version-history":[{"count":8,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/63696\/revisions"}],"predecessor-version":[{"id":63717,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/63696\/revisions\/63717"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=63696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=63696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=63696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}