Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-108341

Add support for std::numbers::e_v<qfloat16> etc

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • P2: Important
    • None
    • None
    • Core: Other
    • None

    Description

      FP types are supposed to have typed mathematical constants in <numbers> (cf. epic). For any std::floating_point T, that is done by the std library. We're not allowed to specialize std::is_floating_point for qfloat16 (that would be UB: https://en.cppreference.com/w/cpp/types/is_floating_point), so the library will not provide these constants for qfloat16 for us. We're allowed (http://eel.is/c++draft/numbers#math.constants-2) to add our own specializations, and that's what we should do.

      The problem is that qfixed16(float) isn't constexpr (→ QTBUG-116079), so, like for the existing std::numeric_limits specialization, we need to use the Wrap mechanism, otherwise we could just have said

      template <> inline constexpr pi<qfloat16> = qfixed16(pi<float>);
      ~~~
      

      Acceptance criteria: The following test passes:

      #ifndef __cpp_lib_math_constants
          QSKIP("This test requires C++20 <numbers> support enabled in the compiler.");
      #else
          using namespace std::numbers;
      #define CHECK(constant) \
          QCOMPARE_EQ(qfloat16(std::numbers:: constant ## _v<float>   ), \
                               std::numbers:: constant ## _v<qfloat16>)
          CHECK(e);
          CHECK(log2e);
          CHECK(log10e);
          CHECK(pi);
          CHECK(inv_pi);
          CHECK(ln2);
          CHECK(ln10);
          CHECK(sqrt2);
          CHECK(sqrt3);
          CHECK(inv_sqrt3);
          CHECK(egamma);
          CHECK(phi);
      #undef CHECK
      #endif // __cpp_lib_math_constants
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              cnn Qt Core & Network
              mmutz Marc Mutz
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes