From 91b1c152336c320e0125c9fb96f46c513b8c6aab Mon Sep 17 00:00:00 2001 From: Patrick Zeinert Date: Wed, 6 May 2020 16:10:06 -0400 Subject: [PATCH] Change "%" op from integer to floating point Details are in issue #8. If accepted, users who are expecting `{"%": [10.5, 2]}` to result in 1 instead of 0.5 will be unhappy. Hence some might consider this a breaking change instead of a bugfix. JavaScript users are already receiving float modulo values, so this would align JS and PHP in terms of features. An alternative would be to make two new ops for `intmod` and `floatmod` for explicit behaviors. --- src/JWadhams/JsonLogic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JWadhams/JsonLogic.php b/src/JWadhams/JsonLogic.php index f0d18a0..ac7068f 100644 --- a/src/JWadhams/JsonLogic.php +++ b/src/JWadhams/JsonLogic.php @@ -93,7 +93,7 @@ public static function apply($logic = [], $data = []) return ($a <= $b) and ($b <= $c) ; }, '%' => function ($a, $b) { - return $a % $b; + return fmod($a, $b); }, '!!' => function ($a) { return static::truthy($a);