mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
The previous implementation intercepted `n / 0` and `n % 0` and returned `.null`, on the rationale that `null` is friendlier for rule authors and matches the engine's "missing value" convention. That's the last remaining intentional deviation from `json-logic-js` in this file — remove it for full spec parity. `json-logic-js` delegates `/` and `%` to native JS arithmetic, which follows IEEE 754: `n / 0` is `±Infinity` (sign matches the dividend), `0 / 0` is `NaN`, and any `n % 0` is `NaN`. Swift's `Double` operators and `truncatingRemainder(dividingBy:)` already produce these IEEE values, so the fix is just dropping the divisor==0 short-circuit and wrapping the result in `.float`. Tests: - Replace `testDivByZeroReturnsNull` with `testDivByZeroFollowsIeee754` pinning all three cases (`+Infinity`, `-Infinity`, `NaN`). - Replace `testModByZeroReturnsNull` with `testModByZeroIsNan` covering `7 % 0` and `0 % 0`. - Update the `1 / null` / `1 % null` cases inside `testSubDivAndModUseToNumberPerSpec` (divisor coerces to 0 → `+Infinity` / `NaN` instead of `.null`). Co-authored-by: Cursor <cursoragent@cursor.com>