Skip to content

Commit 838a05a

Browse files
author
Henry Snoek
committed
59 added fallback in case the BCMath extension isn't installed
1 parent b5e8ed1 commit 838a05a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Ladybug/Type/Float.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class Float extends AbstractType
3232
/** @var string $mathConstant Mathematical constant name */
3333
protected $mathConstant = null;
3434

35-
3635
/**
3736
* Constructor.
3837
*/
@@ -112,8 +111,15 @@ public function detectMathConstant($var, $precision)
112111
);
113112

114113
foreach ($constants as $name => $item) {
115-
if (0 === bccomp($var, $item['value'], max($precision - 1, $item['min_precision']))) {
116-
return $name;
114+
if (extension_loaded('bcmath')) {
115+
if (0 === bccomp($var, $item['value'], max($precision - 1, $item['min_precision']))) {
116+
return $name;
117+
}
118+
} else {
119+
$p = max($precision - 1, $item['min_precision']);
120+
if (number_format($var, $p) === number_format($item['value'], $p)) {
121+
return $name;
122+
}
117123
}
118124
}
119125

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

128-
129134
}

0 commit comments

Comments
 (0)