From 838a05a04f8e1916368d40eb59fef717e260d547 Mon Sep 17 00:00:00 2001 From: Henry Snoek Date: Sat, 23 Aug 2014 14:34:17 +0200 Subject: [PATCH] 59 added fallback in case the BCMath extension isn't installed --- src/Ladybug/Type/Float.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Ladybug/Type/Float.php b/src/Ladybug/Type/Float.php index 1a14e84..4349a79 100644 --- a/src/Ladybug/Type/Float.php +++ b/src/Ladybug/Type/Float.php @@ -32,7 +32,6 @@ class Float extends AbstractType /** @var string $mathConstant Mathematical constant name */ protected $mathConstant = null; - /** * Constructor. */ @@ -112,8 +111,15 @@ public function detectMathConstant($var, $precision) ); foreach ($constants as $name => $item) { - if (0 === bccomp($var, $item['value'], max($precision - 1, $item['min_precision']))) { - return $name; + if (extension_loaded('bcmath')) { + if (0 === bccomp($var, $item['value'], max($precision - 1, $item['min_precision']))) { + return $name; + } + } else { + $p = max($precision - 1, $item['min_precision']); + if (number_format($var, $p) === number_format($item['value'], $p)) { + return $name; + } } } @@ -125,5 +131,4 @@ public function getDecimals() return $this->decimals; } - }