New submission from STINNER Victor <vstin...@redhat.com>:
Extract of Python 2.7, Modules/audioop.c: static int fbound(double val, double minval, double maxval) { if (val > maxval) val = maxval; else if (val < minval + 1) val = minval; return val; } Example of usage: double factor, fval, maxval, minval; int len, size, val = 0; fval = (double)val*factor; val = (int)floor(fbound(fval, minval, maxval)); It seems wrong to me to call floor() with an integer. Why fbound() doesn't return a double? fbound() has been modified to explicitly cast its result to an int in the master branch: static int fbound(double val, double minval, double maxval) { if (val > maxval) val = maxval; else if (val < minval + 1) val = minval; return (int)val; } But master still uses something like: val = floor(fbound(val, minval, maxval)); It seems like fbound() result is always passed into floor(). Maybe floor() should be moved into fbound()? Attached PR changes fbound() to round correctly: call floor() into fbound(). -- I looked at the code because of the following compiler warning on Python 2.7: [00:02:21] ..\Modules\audioop.c(38): warning C4244: 'return' : conversion from 'double' to 'int', possible loss of data [C:\projects\cpython\PCbuild\pythoncore.vcxproj] ---------- components: Extension Modules messages: 318808 nosy: vstinner priority: normal severity: normal status: open title: audioop.c: fbound() casts double to int for its return value versions: Python 2.7, Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33781> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com