From cc92c6648e3d180745cc63226e8e272ca2a90cd8 Mon Sep 17 00:00:00 2001 From: Ikko Ashimine Date: Sun, 17 Nov 2019 14:12:39 +0900 Subject: [PATCH] FLOOR() function accept negative number and negative significance Closes #1245 --- CHANGELOG.md | 2 +- src/PhpSpreadsheet/Calculation/MathTrig.php | 4 +++- tests/data/Calculation/MathTrig/FLOOR.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fb8791b..975c0ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Fixed -- ... +- FLOOR() function accept negative number and negative significance [#1245](https://github.com/PHPOffice/PhpSpreadsheet/pull/1245) ## [1.10.0] - 2019-11-18 diff --git a/src/PhpSpreadsheet/Calculation/MathTrig.php b/src/PhpSpreadsheet/Calculation/MathTrig.php index 30071c2d..fc9211b8 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig.php @@ -301,7 +301,9 @@ class MathTrig return Functions::DIV0(); } elseif ($number == 0.0) { return 0.0; - } elseif (self::SIGN($number) == self::SIGN($significance)) { + } elseif (self::SIGN($significance) == 1) { + return floor($number / $significance) * $significance; + } elseif (self::SIGN($number) == -1 && self::SIGN($significance) == -1) { return floor($number / $significance) * $significance; } diff --git a/tests/data/Calculation/MathTrig/FLOOR.php b/tests/data/Calculation/MathTrig/FLOOR.php index 4b2bd4a2..7d408173 100644 --- a/tests/data/Calculation/MathTrig/FLOOR.php +++ b/tests/data/Calculation/MathTrig/FLOOR.php @@ -12,7 +12,7 @@ return [ -2, ], [ - '#NUM!', + -4, -2.5, 2, ],