New submission from Joël Larose <joel.lar...@gmail.com>: If `math.nan` is the first argument for either max() or min(), the result is always `nan`, regardless of the other values in the results. However, if `nan` is in any other position in the arguments list, the result is always what you would expect if `nan` was not in the arguments list.
E.g. from math import nan, inf >>> max(nan, 5, 3, 0) nan >>> min(nan, 5, 3, 0) nan >>> min(nan, 5, 3, 0, inf, -inf) nan >>> max(nan, 5, 3, 0, inf, -inf) nan >>> max(inf, 5, 3, 0, nan, -inf) inf >>> max(8, inf, 5, 3, 0, nan, -inf) inf >>> min(8, inf, 5, 3, 0, nan, -inf) -inf >>> min(8, nan, inf, 5, 3, 0, nan, -inf) -inf >>> max(8, nan, inf, 5, 3, 0, nan, -inf) inf >>> max(8, 5, 3, 0, nan) 8 As you can see, the results for min() and max() are inconsistent for `nan` depending on whether it's the first argument or not. I would prefer for min() and max() to ignore `nan` unless all arguments are `nan`. However, the other path for consistent behaviour is to return `nan` if any of the arguments are `nan`. ---------- components: Interpreter Core messages: 395497 nosy: joel.larose priority: normal severity: normal status: open title: Inconsistent results for min() and max() with math.nan as argument type: behavior versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44370> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com