Skip to content

Commit

Permalink
Merge pull request #62 from snoek09/issue_59_fix_missing_bcmath_exten…
Browse files Browse the repository at this point in the history
…sion

59 added fallback in case the BCMath extension isn't installed
  • Loading branch information
raulfraile committed Aug 23, 2014
2 parents d26a66d + 838a05a commit 1fb3682
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Ladybug/Type/Float.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class Float extends AbstractType
/** @var string $mathConstant Mathematical constant name */
protected $mathConstant = null;


/**
* Constructor.
*/
Expand Down Expand Up @@ -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;
}
}
}

Expand All @@ -125,5 +131,4 @@ public function getDecimals()
return $this->decimals;
}


}

0 comments on commit 1fb3682

Please sign in to comment.