Vector Class Discussion

 
thread Please add fabs() - Ilja Honkonen - 2014-10-19
last replythread Please add fabs() - Agner - 2014-10-19
last replythread Please add fabs() - Ilja Honkonen - 2014-10-19
last reply Please add fabs() - Agner - 2014-10-19
 
Please add fabs()
Author:  Date: 2014-10-19 08:04
Hello
C++ has fabs in addition to abs (http://en.cppreference.com/w/cpp/numeric/math/fabs) and fabs is the only way to get a floating point result with an integer argument (with C++11: double fabs( Integral arg );). To be closer to the standard e.g. Vec4i argument should produce a Vec4d result but maybe producing a result with same number of total bits would be less surprising or easier to work with. In either case please add, thanks!
   
Please add fabs()
Author: Agner Date: 2014-10-19 10:56
The vector class library was never intended to make vector versions of every function in the C++ standard. The vector classes don't have implicit type conversions between different integer sizes, between integer and float, between float and double, etc. anyway. It is intended to make code faster and should not allow implicit conversions or other functions that would make bad performance.

If you need a particular function, you may define it yourself, e.g.

static inline Vec8f fabs(Vec8i const & x) {
    return abs(to_float(x));
}
   
Please add fabs()
Author:  Date: 2014-10-19 11:07
Ok, what about renaming functions to, or adding ones with, the corresponding standard name, e.g. en.cppreference.com/w/cpp/numeric/math/fma vs vectorclass' mul_add?
   
Please add fabs()
Author: Agner Date: 2014-10-19 13:08
Thanks for the reference to the fma function. However, std::fma is guaranteed to have infinite precision for the intermediate product, while my mul_add has only standard precision if no FMA instruction set is supported. Only my mul_sub_x is certain to have _almost_ infinite precision. Secondly, there seem to be no standard names for mul_sub and nmul_add.