From 56114d99ce650c6e797a74c464e1b91ef6c04c71 Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Mon, 2 May 2016 23:06:17 +0200 Subject: [PATCH] fix param casting for hhvm compatibility --- src/Phpml/Clustering/KMeans/Point.php | 2 +- src/Phpml/Math/Distance/Euclidean.php | 2 +- src/Phpml/Math/Matrix.php | 4 ++-- src/Phpml/Math/Statistic/Correlation.php | 2 +- src/Phpml/Math/Statistic/StandardDeviation.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Phpml/Clustering/KMeans/Point.php b/src/Phpml/Clustering/KMeans/Point.php index 9ff4b45..eb5bb78 100644 --- a/src/Phpml/Clustering/KMeans/Point.php +++ b/src/Phpml/Clustering/KMeans/Point.php @@ -49,7 +49,7 @@ class Point implements ArrayAccess $distance += $difference * $difference; } - return $precise ? sqrt($distance) : $distance; + return $precise ? sqrt((float)$distance) : $distance; } /** diff --git a/src/Phpml/Math/Distance/Euclidean.php b/src/Phpml/Math/Distance/Euclidean.php index cca8f2b..1b6083b 100644 --- a/src/Phpml/Math/Distance/Euclidean.php +++ b/src/Phpml/Math/Distance/Euclidean.php @@ -30,6 +30,6 @@ class Euclidean implements Distance $distance += pow($a[$i] - $b[$i], 2); } - return sqrt($distance); + return sqrt((float)$distance); } } diff --git a/src/Phpml/Math/Matrix.php b/src/Phpml/Math/Matrix.php index 7c04119..d15629a 100644 --- a/src/Phpml/Math/Matrix.php +++ b/src/Phpml/Math/Matrix.php @@ -147,7 +147,7 @@ class Matrix for ($j = 0; $j < $this->columns; ++$j) { $subMatrix = $this->crossOut(0, $j); $minor = $this->matrix[0][$j] * $subMatrix->getDeterminant(); - $determinant += fmod($j, 2) == 0 ? $minor : -$minor; + $determinant += fmod((float)$j, 2.0) == 0 ? $minor : -$minor; } } @@ -236,7 +236,7 @@ class Matrix for ($i = 0; $i < $this->rows; ++$i) { for ($j = 0; $j < $this->columns; ++$j) { $minor = $this->crossOut($i, $j)->getDeterminant(); - $newMatrix[$i][$j] = fmod($i + $j, 2) == 0 ? $minor : -$minor; + $newMatrix[$i][$j] = fmod((float)($i + $j), 2.0) == 0 ? $minor : -$minor; } } diff --git a/src/Phpml/Math/Statistic/Correlation.php b/src/Phpml/Math/Statistic/Correlation.php index 1d2e8ac..842008c 100644 --- a/src/Phpml/Math/Statistic/Correlation.php +++ b/src/Phpml/Math/Statistic/Correlation.php @@ -38,7 +38,7 @@ class Correlation $b2 = $b2 + pow($b, 2); } - $corr = $axb / sqrt($a2 * $b2); + $corr = $axb / sqrt((float)($a2 * $b2)); return $corr; } diff --git a/src/Phpml/Math/Statistic/StandardDeviation.php b/src/Phpml/Math/Statistic/StandardDeviation.php index 2b03c54..8ecb234 100644 --- a/src/Phpml/Math/Statistic/StandardDeviation.php +++ b/src/Phpml/Math/Statistic/StandardDeviation.php @@ -39,6 +39,6 @@ class StandardDeviation --$n; } - return sqrt($carry / $n); + return sqrt((float)($carry / $n)); } }