Hi Victor, The fallback implementations in the various libc take care to preserve the correct rounding behaviour.
Let me stress that *fused* multiply-add means the specific rounding behaviour as defined in the standard IEEE-754 2008 (i.e. with guaranteed *no* intermediate rounding). So the following would not be a valid FMA fallback double bad_fma(double x, double y, double z) { return x*y + z; } Now in practice, people want FMA for two reasons. 1. They need the additional precision. 2. They want the performance of a hardware FMA instruction. Now, admittedly, the second category would be satisfied with the bad_fma fallback. However, I don't think 2. is a very compelling reason for fma *in pure Python code*, since the performance advantage would probably be dwarfed by interpreter overhead. So I would estimate that approx. 100% of the target audience of math.fma would want to use it for the increased accuracy. So providing a fallback which does not, in fact, give that accuracy would not make people happy. Upshot: if we want to provide a software fallback in the Python code, we need to do something slow and complicated like musl does. Possibly by actually using the musl code. Either that, or we rely on the Python-external libc implementation always. Stephan 2017-01-16 9:45 GMT+01:00 Victor Stinner <victor.stin...@gmail.com>: > 2017-01-15 18:25 GMT+01:00 Juraj Sukop <juraj.su...@gmail.com>: > > C99 includes `fma` function to `math.h` [6] and emulates the calculation > if > > the FMA instruction is not present on the host CPU [7]. > > If even the libc function has a fallback on x*y followed by +z, it's > fine to add such function to the Python stdlib. It means that Python > can do the same if the libc lacks a fma() function. In the math > module, the trend is more to implement missing functions or add > special code to workaround bugs or limitations of libc functions. > > Victor > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/