This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] std::experimental::gcd and std::experimental::lcd


On 02/05/15 18:27 +0200, Marc Glisse wrote:
On Sat, 2 May 2015, Jonathan Wakely wrote:

These where simple to implement (almost too simple ... I probably
got something wrong!)

I didn't remember that std::abs works for unsigned. It will need more work for performance, but that can certainly be done later (I didn't look at the code beyond checking what you meant by "simple").

std::abs seems to work fine for unsigned, the overload in <cmath> for
integral types just uses __builtin_fabs. Maybe it would be better for
gcd() to just use that directly instead of including <cmath> (as
attached, which also removes the qualification on the call to gcd
because the functions only work for integral types which have no
associated namespaces anyway).

(Apart from using common_type_t, which is easy to change, these
functions meet the simpler rules for C++11 constexpr, so moving them
out of <experimental/numeric> would probably allow <ratio> to be
greatly simplified. I don't plan on doing that myself any time soon,
but it would make sense to do it some day.)

gcd is not really the hard part in ratio. But constexpr should help, it made sense not to have it in tr1, but I don't remember why we didn't use it in the more recent changes (2011, the compiler probably already supported constexpr). Maybe the interesting functions were too hard to write as one-liners...

<ratio> was added to libstdc++ in 2008 so I think the constexpr
support was not good enough at the time.

Attachment: abs.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]