rfc:php_ini_bcmath_default

This is an old revision of the document!


Request for Comments: PHP.INI Setting to Force All Math Operations Through BCMath Library

Introduction

The problems of floating point math are well documented, and a grand gotcha to any non-computer science student user of PHP (or any other programming language). I still remember my shock and surprise at this (since I'm not a computer science student by background):

34.17 + 18.83 = 52.99999999999999999999999

The BCMath library exists to avoid this problem, but code can become very, very hard to read if a lot of numerical calculations are going on.

Proposal

A php.ini setting that, when set true, routes all the floating point math operator functions to the bcmath library. If that library isn't enabled and this setting is set to true an E_ERROR is raised. With this setting in place

34.17 + 18.83 = 53.00

Assuming a scale of 2. The setting can be activated at runtime, by htaccess or in the core php.ini file.

Note that this proposal is just for the math operators, not for all the math functions. Even with this setting on, ++ and -- would increment/decrement by 1.

Potential Problems

This will be a performance hit when enabled. Other than that though I can't think of any major problems.

Changelog

2012-03-06 Created.

rfc/php_ini_bcmath_default.1331068610.txt.gz · Last modified: 2017/09/22 13:28 (external edit)