Re: Proposal to add attribute 'step' to FloatField and DecimalField

2021-03-22 Thread 'Adam Johnson' via Django developers (Contributions to Django itself)
Use the modulo operator In [1]: 4.5 % 1.5 Out[1]: 0.0 https://en.wikipedia.org/wiki/Modulo_operation https://docs.python.org/3/reference/expressions.html?highlight=modulo#binary-arithmetic-operations On Sun, 21 Mar 2021 at 23:47, Jacob Rief wrote: > Say, you have a value and step, both are flo

Re: Fellow Reports - March 2021

2021-03-22 Thread Mariusz Felisiak
Week ending March 21, 2021 *Triaged: * https://code.djangoproject.com/ticket/32547 - assertHTMLEqual()/assertHTMLNotEqual() allow invalid HTML. (accepted) https://code.djangoproject.com/ticket/32549 - Add `Q.empty()` to check for nested empty Q objects like `Q(Q())` (wontfix) https:/

Re: Proposal to add attribute 'step' to FloatField and DecimalField

2021-03-22 Thread Jacob Rief
The problem with modulo on floats is, that due to rounding errors it often created weird results, for instance in Python-3.8 this happens: 3.5 % 0.1 = 0.09981 This btw. also applies to the builtin divmod and math.fmod functions. Therefore I proposed to do it via classic division and ch

Re: Proposal to add attribute 'step' to FloatField and DecimalField

2021-03-22 Thread James Bennett
There are ways to check "close enough" equality for floats. There's even the math.isclose() function which is arbitrarily tune-able: https://docs.python.org/3/library/math.html#math.isclose -- You received this message because you are subscribed to the Google Groups "Django developers (Contrib

Re: Proposal to add attribute 'step' to FloatField and DecimalField

2021-03-22 Thread Kapil Bansal
I do something similar to what math.isclose() provides. Can anyone please review this PR:- https://github.com/django/django/pull/14162 On Mon, Mar 22, 2021, 4:53 PM James Bennett wrote: > There are ways to check "close enough" equality for floats. There's > even the math.isclose() function which