public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/54686] New: std::abs (long long) resorts to std::abs (double) if llabs is absent
@ 2012-09-23 20:21 olegendo at gcc dot gnu.org
  2012-09-23 20:42 ` [Bug target/54686] " paolo.carlini at oracle dot com
                   ` (41 more replies)
  0 siblings, 42 replies; 43+ messages in thread
From: olegendo at gcc dot gnu.org @ 2012-09-23 20:21 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54686

             Bug #: 54686
           Summary: std::abs (long long) resorts to std::abs (double) if
                    llabs is absent
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: olegendo@gcc.gnu.org


I'm not sure, whether this is intentional or not, but on my SH xgcc setup with
newlib 1.20.0 the following:

#include <cstddef>
#include <cstdint>
#include <algorithm>

int64_t test (int64_t* b)
{
  return std::abs (*b);
}

ends up doing an abs of a double.
Looking at the preprocessed source, the following looks suspicious:

  template<typename _Tp>
    inline constexpr
    typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
                                    double>::__type
    abs(_Tp __x)
    { return __builtin_fabs(__x); }

I guess since there's no overload for long long due to the lack of llabs, the
template function above is taken instead.  However, this can't be right and
won't actually work for large 64 bit int numbers.
Although probably the proper fix would be to add llabs to newlib, I think the
enable_if above should also check whether the integer has any chance of fitting
into the double.


^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2012-10-05 19:10 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-23 20:21 [Bug libstdc++/54686] New: std::abs (long long) resorts to std::abs (double) if llabs is absent olegendo at gcc dot gnu.org
2012-09-23 20:42 ` [Bug target/54686] " paolo.carlini at oracle dot com
2012-09-23 20:43 ` paolo.carlini at oracle dot com
2012-09-23 20:49 ` paolo.carlini at oracle dot com
2012-09-23 20:57 ` paolo.carlini at oracle dot com
2012-09-23 21:00 ` glisse at gcc dot gnu.org
2012-09-23 21:14 ` olegendo at gcc dot gnu.org
2012-09-23 21:15 ` paolo.carlini at oracle dot com
2012-09-23 21:21 ` olegendo at gcc dot gnu.org
2012-09-23 21:21 ` paolo.carlini at oracle dot com
2012-09-23 21:38 ` glisse at gcc dot gnu.org
2012-09-23 21:51 ` olegendo at gcc dot gnu.org
2012-09-23 22:11 ` glisse at gcc dot gnu.org
2012-09-23 22:22 ` glisse at gcc dot gnu.org
2012-09-23 22:34 ` olegendo at gcc dot gnu.org
2012-09-23 22:43 ` paolo.carlini at oracle dot com
2012-09-23 22:53 ` paolo.carlini at oracle dot com
2012-09-23 22:55 ` glisse at gcc dot gnu.org
2012-09-23 23:02 ` glisse at gcc dot gnu.org
2012-09-23 23:04 ` paolo.carlini at oracle dot com
2012-09-23 23:05 ` olegendo at gcc dot gnu.org
2012-09-23 23:06 ` paolo.carlini at oracle dot com
2012-09-23 23:09 ` glisse at gcc dot gnu.org
2012-09-23 23:12 ` paolo.carlini at oracle dot com
2012-09-23 23:16 ` glisse at gcc dot gnu.org
2012-09-23 23:18 ` paolo.carlini at oracle dot com
2012-09-24  0:16 ` kkojima at gcc dot gnu.org
2012-09-24  5:33 ` glisse at gcc dot gnu.org
2012-09-24  9:27 ` paolo.carlini at oracle dot com
2012-09-30 17:48 ` olegendo at gcc dot gnu.org
2012-09-30 18:18 ` paolo.carlini at oracle dot com
2012-10-04 22:27 ` glisse at gcc dot gnu.org
2012-10-05 16:21 ` glisse at gcc dot gnu.org
2012-10-05 16:24 ` glisse at gcc dot gnu.org
2012-10-05 16:25 ` paolo.carlini at oracle dot com
2012-10-05 16:34 ` glisse at gcc dot gnu.org
2012-10-05 16:39 ` paolo.carlini at oracle dot com
2012-10-05 16:47 ` glisse at gcc dot gnu.org
2012-10-05 16:58 ` paolo.carlini at oracle dot com
2012-10-05 17:02 ` paolo.carlini at oracle dot com
2012-10-05 17:04 ` glisse at gcc dot gnu.org
2012-10-05 17:09 ` paolo.carlini at oracle dot com
2012-10-05 19:10 ` glisse at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).