This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [patch] std::experimental::gcd and std::experimental::lcd
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 2 May 2015 18:16:46 +0100
- Subject: Re: [patch] std::experimental::gcd and std::experimental::lcd
- Authentication-results: sourceware.org; auth=none
- References: <20150502151849 dot GZ3618 at redhat dot com> <alpine dot DEB dot 2 dot 11 dot 1505021813010 dot 4001 at laptop-mg dot saclay dot inria dot fr> <20150502164728 dot GA3618 at redhat dot com> <alpine dot DEB dot 2 dot 11 dot 1505021904330 dot 4001 at laptop-mg dot saclay dot inria dot fr>
On 02/05/15 19:07 +0200, Marc Glisse wrote:
On Sat, 2 May 2015, Jonathan Wakely wrote:
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.
That's bad! You don't want to go through floating point, that cannot
even represent int64_t accurately.
Good point - we should fix <cmath> then!
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).
Actually you use __builtin_abs (no 'f') in the patch, which apparently
casts to int, that's even worse...
Oops, that's a typo (I didn't even test that change).
<ratio> was added to libstdc++ in 2008 so I think the constexpr
support was not good enough at the time.
Yes, but we modified a few pieces with Paolo in 2011, and those could
have used constexpr I guess.
Ah I see. What we have now works, so it's not a priority to try and
replace bits of it with constexpr functions.