pmforms icon indicating copy to clipboard operation
pmforms copied to clipboard

Slider: Add validation considering steps

Open PJZ9n opened this issue 3 years ago • 4 comments

PJZ9n avatar Jul 08 '22 22:07 PJZ9n

This is unreliable because of floating-point errors. There's a very good chance that this check will fail in valid circumstances because of it.

dktapps avatar Jul 09 '22 13:07 dktapps

I think that it is necessary to calculate with the same accuracy as MCPE to solve it accurately, but as an alternative method, can the problem be solved by aligning the values ​​according to the number of digits of the step? If so, I don't think there is a practical problem.

PJZ9n avatar Jul 10 '22 11:07 PJZ9n

I think that it is necessary to calculate with the same accuracy as MCPE to solve it accurately, but as an alternative method, can the problem be solved by aligning the values ​​according to the number of digits of the step? If so, I don't think there is a practical problem.

No. It's like the old meme about 0.1 + 0.2 != 0.3. MCPE uses int32 precision, the server uses int64. Therefore there will always be discrepancies.

dktapps avatar Jul 10 '22 16:07 dktapps

$step = 0.001;
$value = 6.006000518798828;
$a = round($value, strlen((string)$step));//float(6.006)
$b = $a / $step;//float(6006)
var_dump(ctype_digit((string)$b));//bool(true)

However, this is a successful calculation. Of course there is a possibility of an error, but is this a practical problem?

PJZ9n avatar Jul 10 '22 19:07 PJZ9n