[wp-trac] [WordPress Trac] #47454: BC Math isn't used in WordPress core
    WordPress Trac 
    noreply at wordpress.org
       
    Tue Jun  4 12:21:51 UTC 2019
    
    
  
#47454: BC Math isn't used in WordPress core
---------------------------------------------------+---------------------
 Reporter:  bronsonquick                           |       Owner:  (none)
     Type:  defect (bug)                           |      Status:  new
 Priority:  normal                                 |   Milestone:  5.3
Component:  Administration                         |     Version:  5.2
 Severity:  normal                                 |  Resolution:
 Keywords:  has-patch site-health has-screenshots  |     Focuses:
---------------------------------------------------+---------------------
Comment (by jrf):
 Ok, so someone kindly pointed me to this discussion. (Thanks @jipmoors)
 First off: let me make sure everyone knows what
 [https://www.php.net/manual/en/ref.bc.php BCMath] does: it provides
 calculation functions and it is the **''only reliable way to do
 calculations with floating point numbers in PHP''** which is available by
 default.
 If you want more details - read the big reddish warning on the PHP manual
 page about floats: https://www.php.net/manual/en/language.types.float.php
 Oh and just for fun and to understand the impact, try this code snippet
 in:
 {{{#!php
 <?php
 $x = (int) ( ( 0.1 + 0.7 ) * 10 );
 var_dump($x);
 }}}
 This means that **''any calculations involving divisions, percentages and
 money should use BCMath''** as otherwise they **will** be buggy and
 unreliable.
 I dearly hope that plugins like WooCommerce do this correctly....
 BCMath has shipped with PHP since PHP 4.0.4.
 The GMP can be seen as a valid alternative, but using that with floating
 point numbers is more involved and it doesn't ship with PHP by default.
 > BC Math isn't used in core, therefore it's a bug to unnecessarily list
 it as a recommended extension.
 If Core doesn't use it, it shouldn't be a ''required'' extension, but it
 surely should be a ''recommended'' extension.
 Also: I wonder if there aren't places in Core where calculations are done
 with floats which ''should'' use BCMath.
 > bcmath isn't listed there anymore so I'm guessing that was updated which
 is good.
 I'd recommend bringing it back.
 > Since Site Health is a new thing, why not make it cover only Core, while
 providing ways for plugins and themes to add requirements.
 I'd fully support adding a way for plugins to hook into this.
-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47454#comment:18>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
    
    
More information about the wp-trac
mailing list