pkg/math: fix MultipleOf algorithm
math.MultipleOf currently has many false negatives.
The current algorithm functions as follows.
Given math.MultipleOf(x, y):
- use decimal precision of 1
- divide x by y
- check if the resulting apd.Condition is inexact, indicating digits
were discarded
This is incorrect, because any time the result of the quotient
requires more than the provided precision (i.e. 1), we will assume the
result is false.
For example, math.MultipleOf(22, 2) is false because the result is 11,
requiring a precision of 2.
To fix this, the algorithm is adjusted to:
- divide x by y
- return whether the result is an integer, by ensuring the
fractional part is exactly 0
Fixes #2926.
Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Change-Id: Ie978ba0880f7260753eb5288b7c0b14de1c9c73c
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1193690
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
authored by