public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Implement new SI prefixes in <ratio> for C++23 (P2734R0)
@ 2023-08-24 12:44 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-08-24 12:44 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested x86_64-linux. Pushed to trunk.

-- >8 --

This is a no-op for libstdc++, because our intmax_t is a 64-bit type and
so is incapable of representing the largest and smallest ratios from
C++11, let alone the new ones. I've added them to the file anyway (and
defined the feature test macro) so that if somebody ports libstdc++ to a
target with 128-bit intmax_t then they'll be present.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (__cpp_lib_ratio): Define.
	* include/bits/version.h: Regenerate.
	* include/std/ratio (quecto, ronto, yocto, zepto)
	(zetta, yotta, ronna, quetta): Define.
	* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Adjust
	dg-error line numbers.
---
 libstdc++-v3/include/bits/version.def         |  8 +++
 libstdc++-v3/include/bits/version.h           | 11 ++++
 libstdc++-v3/include/std/ratio                | 56 +++++++++++++------
 .../ratio/operations/ops_overflow_neg.cc      |  6 +-
 4 files changed, 61 insertions(+), 20 deletions(-)

diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def
index b50050440d9..80c13d4a447 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -1582,6 +1582,14 @@ ftms = {
   };
 };
 
+ftms = {
+  name = ratio;
+  values = {
+    v = 202306;
+    cxxmin = 26;
+  };
+};
+
 ftms = {
   name = to_string;
   values = {
diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h
index 8b8c70a6e53..5bddb4b8adc 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -1940,6 +1940,17 @@
 #undef __glibcxx_want_string_resize_and_overwrite
 
 // from version.def line 1586
+#if !defined(__cpp_lib_ratio)
+# if (__cplusplus >  202302L)
+#  define __glibcxx_ratio 202306L
+#  if defined(__glibcxx_want_all) || defined(__glibcxx_want_ratio)
+#   define __cpp_lib_ratio 202306L
+#  endif
+# endif
+#endif /* !defined(__cpp_lib_ratio) && defined(__glibcxx_want_ratio) */
+#undef __glibcxx_want_ratio
+
+// from version.def line 1594
 #if !defined(__cpp_lib_to_string)
 # if (__cplusplus >  202302L) && _GLIBCXX_HOSTED && (__glibcxx_to_chars)
 #  define __glibcxx_to_string 202306L
diff --git a/libstdc++-v3/include/std/ratio b/libstdc++-v3/include/std/ratio
index 1d285bf916f..c87f54fe1a2 100644
--- a/libstdc++-v3/include/std/ratio
+++ b/libstdc++-v3/include/std/ratio
@@ -39,6 +39,9 @@
 #include <type_traits>
 #include <cstdint>		// intmax_t, uintmax_t
 
+#define __glibcxx_want_ratio
+#include <bits/version.h>
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -602,23 +605,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _R1, typename _R2>
     using ratio_subtract = typename __ratio_subtract<_R1, _R2>::type;
 
-
-  typedef ratio<1,       1000000000000000000> atto;
-  typedef ratio<1,          1000000000000000> femto;
-  typedef ratio<1,             1000000000000> pico;
-  typedef ratio<1,                1000000000> nano;
-  typedef ratio<1,                   1000000> micro;
-  typedef ratio<1,                      1000> milli;
-  typedef ratio<1,                       100> centi;
-  typedef ratio<1,                        10> deci;
-  typedef ratio<                       10, 1> deca;
-  typedef ratio<                      100, 1> hecto;
-  typedef ratio<                     1000, 1> kilo;
-  typedef ratio<                  1000000, 1> mega;
-  typedef ratio<               1000000000, 1> giga;
-  typedef ratio<            1000000000000, 1> tera;
-  typedef ratio<         1000000000000000, 1> peta;
-  typedef ratio<      1000000000000000000, 1> exa;
+#if __INTMAX_WIDTH__ >= 96
+# if __cpp_lib_ratio >= 202306L
+#  if __INTMAX_WIDTH__ >= 128
+  using quecto = ratio<                  1, 1000000000000000000000000000000>;
+#  endif
+  using ronto  = ratio<                     1, 1000000000000000000000000000>;
+# endif
+  using yocto  = ratio<                        1, 1000000000000000000000000>;
+  using zepto  = ratio<                        1,    1000000000000000000000>;
+#endif
+  using atto   = ratio<                        1,       1000000000000000000>;
+  using femto  = ratio<                        1,          1000000000000000>;
+  using pico   = ratio<                        1,             1000000000000>;
+  using nano   = ratio<                        1,                1000000000>;
+  using micro  = ratio<                        1,                   1000000>;
+  using milli  = ratio<                        1,                      1000>;
+  using centi  = ratio<                        1,                       100>;
+  using deci   = ratio<                        1,                        10>;
+  using deca   = ratio<                       10,                         1>;
+  using hecto  = ratio<                      100,                         1>;
+  using kilo   = ratio<                     1000,                         1>;
+  using mega   = ratio<                  1000000,                         1>;
+  using giga   = ratio<               1000000000,                         1>;
+  using tera   = ratio<            1000000000000,                         1>;
+  using peta   = ratio<         1000000000000000,                         1>;
+  using exa    = ratio<      1000000000000000000,                         1>;
+#if __INTMAX_WIDTH__ >= 96
+  using zetta  = ratio<   1000000000000000000000,                         1>;
+  using yotta  = ratio<1000000000000000000000000,                         1>;
+# if __cpp_lib_ratio >= 202306L
+  using ronna  = ratio<1000000000000000000000000000,                      1>;
+#  if __INTMAX_WIDTH__ >= 128
+  using quetta = ratio<1000000000000000000000000000000,                   1>;
+#  endif
+# endif
+#endif
 
   /// @} group ratio
 _GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc
index 2e2a59c164c..62034e42a75 100644
--- a/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow_neg.cc
@@ -43,9 +43,9 @@ test02()
 // { dg-error "expected initializer" "" { target *-*-* } 35 }
 // { dg-error "expected initializer" "" { target *-*-* } 37 }
 // { dg-error "overflow in addition" "" { target *-*-* } 0 }
-// { dg-error "overflow in multiplication" "" { target *-*-* } 98 }
-// { dg-error "overflow in multiplication" "" { target *-*-* } 100 }
-// { dg-error "overflow in multiplication" "" { target *-*-* } 102 }
+// { dg-error "overflow in multiplication" "" { target *-*-* } 101 }
+// { dg-error "overflow in multiplication" "" { target *-*-* } 103 }
+// { dg-error "overflow in multiplication" "" { target *-*-* } 105 }
 // { dg-error "overflow in constant expression" "" { target *-*-* } 0 }
 // { dg-error "narrowing conversion" "" { target *-*-* } 0 }
 // { dg-prune-output "out of range" }
-- 
2.41.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-24 12:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-24 12:44 [committed] libstdc++: Implement new SI prefixes in <ratio> for C++23 (P2734R0) Jonathan Wakely

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).