public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libquadmath/109758] New: quadmath abs
@ 2023-05-06 17:44 g.peterhoff@t-online.de
  2023-05-06 20:33 ` [Bug libstdc++/109758] " jakub at gcc dot gnu.org
                   ` (18 more replies)
  0 siblings, 19 replies; 20+ messages in thread
From: g.peterhoff@t-online.de @ 2023-05-06 17:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109758

            Bug ID: 109758
           Summary: quadmath abs
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libquadmath
          Assignee: unassigned at gcc dot gnu.org
          Reporter: g.peterhoff@t-online.de
  Target Milestone: ---

Hello gcc-team,
Problem:
#include <boost/cstdfloat.hpp>
#include <iostream>
#include <limits>
#include <cmath>

using T = __float128;

int main()
{
    const T 
        neg_nan_v = -std::numeric_limits<T>::quiet_NaN();

    std::cout << neg_nan_v << std::endl;

    std::cout << "std::abs " << std::abs(neg_nan_v) << std::endl;
    std::cout << "fabsq " << fabsq(neg_nan_v) << std::endl;
    std::cout << "builtin " << __builtin_fabsf128(neg_nan_v) << std::endl;
}

-nan
std::abs -nan
fabsq nan
builtin nan

The problem can be found in bits/std_abs.h:
#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
  __extension__ inline _GLIBCXX_CONSTEXPR
  __float128
  abs(__float128 __x)
  {
   return __x < 0 ? -__x : __x;
  }
#endif

Is this actually correct? If I compile with -U__STRICT_ANSI__ or remove/comment
abs from bits/std_abs.h abs falls back to fabsq, which then also works.
With std::abs(float/double/...) this problem does not occur.

Wouldn't it make sense in principle to also provide a C++ header
(quadmath.hpp)?
#include <quadmath.h>
namespace std
{
math-functions
to_string/to_wstring
to_chars/from_chars
operator<<
operator>>
...
}

thx
Gero

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

end of thread, other threads:[~2024-03-18 14:12 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-06 17:44 [Bug libquadmath/109758] New: quadmath abs g.peterhoff@t-online.de
2023-05-06 20:33 ` [Bug libstdc++/109758] " jakub at gcc dot gnu.org
2023-05-06 22:15 ` [Bug libstdc++/109758] std::abs(__float128) doesn't support NaN redi at gcc dot gnu.org
2023-05-06 22:48 ` g.peterhoff@t-online.de
2023-05-06 22:57 ` redi at gcc dot gnu.org
2023-05-06 23:06 ` g.peterhoff@t-online.de
2023-05-06 23:09 ` redi at gcc dot gnu.org
2023-05-07  0:09 ` g.peterhoff@t-online.de
2023-05-07 10:04 ` jakub at gcc dot gnu.org
2023-05-08  8:29 ` redi at gcc dot gnu.org
2023-05-08  8:31 ` redi at gcc dot gnu.org
2023-05-08  8:47 ` jakub at gcc dot gnu.org
2023-05-08 16:40 ` redi at gcc dot gnu.org
2023-05-11 11:55 ` cvs-commit at gcc dot gnu.org
2023-05-11 11:57 ` redi at gcc dot gnu.org
2023-05-11 12:12 ` redi at gcc dot gnu.org
2023-06-01 22:44 ` cvs-commit at gcc dot gnu.org
2023-06-01 22:45 ` redi at gcc dot gnu.org
2024-03-18 14:05 ` cvs-commit at gcc dot gnu.org
2024-03-18 14:12 ` redi 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).