Skip to content

[libc++][test] Adjust expected hexfloat format #95011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 16, 2024
Merged

Conversation

jakeegan
Copy link
Member

The test expects a hex float format of 0x0p+0, but AIX prints 0x0.0p+0. This change adjusts the test to accept both.

@jakeegan jakeegan requested a review from a team as a code owner June 10, 2024 17:02
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jun 10, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 10, 2024

@llvm/pr-subscribers-libcxx

Author: Jake Egan (jakeegan)

Changes

The test expects a hex float format of 0x0p+0, but AIX prints 0x0.0p+0. This change adjusts the test to accept both.


Patch is 229.17 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/95011.diff

2 Files Affected:

  • (modified) libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp (+251-194)
  • (modified) libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.hex.pass.cpp (+251-194)
diff --git a/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp b/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp
index 21efa978abdcc..caca4bf71d92b 100644
--- a/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp
@@ -17,12 +17,11 @@
 // https://developercommunity.visualstudio.com/t/Printf-formatting-of-float-as-hex-prints/1660844
 // XFAIL: msvc
 
-// XFAIL: LIBCXX-AIX-FIXME
-
 #include <locale>
 #include <ios>
 #include <cassert>
 #include <streambuf>
+#include <sstream>
 #include <cmath>
 #include "test_macros.h"
 #include "test_iterators.h"
@@ -49,6 +48,13 @@ class my_numpunct
     virtual std::string do_grouping() const {return std::string("\1\2\3");}
 };
 
+const std::string hexfloat_fmt(const double& v, const std::ios& ios){
+    std::ostringstream oss;
+    oss.copyfmt(ios);
+    oss << std::noshowpos << std::hexfloat << v;
+    return oss.str();
+}
+
 void test1()
 {
     char str[200];
@@ -60,6 +66,9 @@ void test1()
         std::ios ios(0);
         std::hexfloat(ios);
         // %a
+
+        std::string hf(hexfloat_fmt(0., ios));
+        const std::string padding(25 - hf.length() - 1, '*');
         {
             ios.precision(0);
             {
@@ -70,12 +79,13 @@ void test1()
                         std::noshowpoint(ios);
                         {
                             ios.imbue(lc);
+                            hf = hexfloat_fmt(0., ios);
                             {
                                 ios.width(0);
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0p+0");
+                                    assert(ex == "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -83,7 +93,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0p+0******************");
+                                    assert(ex == "-" + hf + padding);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -91,7 +101,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "******************-0x0p+0");
+                                    assert(ex == padding + "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -99,17 +109,18 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-******************0x0p+0");
+                                    assert(ex == "-" + padding + hf);
                                     assert(ios.width() == 0);
                                 }
                             }
                             ios.imbue(lg);
+                            hf = hexfloat_fmt(0., ios);
                             {
                                 ios.width(0);
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0p+0");
+                                    assert(ex == "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -117,7 +128,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0p+0******************");
+                                    assert(ex == "-" + hf + padding);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -125,7 +136,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "******************-0x0p+0");
+                                    assert(ex == padding + "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -133,7 +144,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-******************0x0p+0");
+                                    assert(ex == "-" + padding + hf);
                                     assert(ios.width() == 0);
                                 }
                             }
@@ -141,12 +152,13 @@ void test1()
                         std::showpoint(ios);
                         {
                             ios.imbue(lc);
+                            hf = hexfloat_fmt(0., ios);
                             {
                                 ios.width(0);
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0.p+0");
+                                    assert(ex == "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -154,7 +166,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0.p+0*****************");
+                                    assert(ex == "-" + hf + padding);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -162,7 +174,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "*****************-0x0.p+0");
+                                    assert(ex == padding + "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -170,17 +182,18 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-*****************0x0.p+0");
+                                    assert(ex == "-" + padding + hf);
                                     assert(ios.width() == 0);
                                 }
                             }
                             ios.imbue(lg);
+                            hf = hexfloat_fmt(0., ios);
                             {
                                 ios.width(0);
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0;p+0");
+                                    assert(ex == "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -188,7 +201,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0;p+0*****************");
+                                    assert(ex == "-" + hf + padding);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -196,7 +209,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "*****************-0x0;p+0");
+                                    assert(ex == padding + "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -204,7 +217,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-*****************0x0;p+0");
+                                    assert(ex == "-" + padding + hf);
                                     assert(ios.width() == 0);
                                 }
                             }
@@ -215,12 +228,13 @@ void test1()
                         std::noshowpoint(ios);
                         {
                             ios.imbue(lc);
+                            hf = hexfloat_fmt(0., ios);
                             {
                                 ios.width(0);
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0p+0");
+                                    assert(ex == "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -228,7 +242,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0p+0******************");
+                                    assert(ex == "-" + hf + padding);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -236,7 +250,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "******************-0x0p+0");
+                                    assert(ex == padding + "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -244,17 +258,18 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-******************0x0p+0");
+                                    assert(ex == "-" + padding + hf);
                                     assert(ios.width() == 0);
                                 }
                             }
                             ios.imbue(lg);
+                            hf = hexfloat_fmt(0., ios);
                             {
                                 ios.width(0);
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0p+0");
+                                    assert(ex == "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -262,7 +277,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0p+0******************");
+                                    assert(ex == "-" + hf + padding);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -270,7 +285,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "******************-0x0p+0");
+                                    assert(ex == padding + "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -278,7 +293,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-******************0x0p+0");
+                                    assert(ex == "-" + padding + hf);
                                     assert(ios.width() == 0);
                                 }
                             }
@@ -286,12 +301,13 @@ void test1()
                         std::showpoint(ios);
                         {
                             ios.imbue(lc);
+                            hf = hexfloat_fmt(0., ios);
                             {
                                 ios.width(0);
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0.p+0");
+                                    assert(ex == "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -299,7 +315,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0.p+0*****************");
+                                    assert(ex == "-" + hf + padding);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -307,7 +323,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "*****************-0x0.p+0");
+                                    assert(ex == padding + "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -315,17 +331,18 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-*****************0x0.p+0");
+                                    assert(ex == "-" + padding + hf);
                                     assert(ios.width() == 0);
                                 }
                             }
                             ios.imbue(lg);
+                            hf = hexfloat_fmt(0., ios);
                             {
                                 ios.width(0);
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0;p+0");
+                                    assert(ex == "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -333,7 +350,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "-0x0;p+0*****************");
+                                    assert(ex == "-" + hf + padding);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -341,7 +358,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                     std::string ex(str, base(iter));
-                                    assert(ex == "*****************-0x0;p+0");
+                                    assert(ex == padding + "-" + hf);
                                     assert(ios.width() == 0);
                                 }
                                 ios.width(25);
@@ -349,7 +366,7 @@ void test1()
                                 {
                                     cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v);
                                 ...
[truncated]

Copy link

github-actions bot commented Jun 10, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Member

@daltenty daltenty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the printf behaviour your seeing is invalid. The test sets a precision of zero, and according to the C standard:

the number of hexadecimal digits after ("the decimal point character") is equal to the precision; .. if the precision is zero and the # flag is not specified, no
decimal-point character appears."

@jakeegan jakeegan closed this Jun 11, 2024
@jakeegan jakeegan deleted the print_hex branch June 11, 2024 19:01
@daltenty
Copy link
Member

daltenty commented Jun 14, 2024

I think the printf behaviour your seeing is invalid. The test sets a precision of zero, and according to the C standard:

Actually turns out the C++ standard has a specific carve-out for precision in the case of hexfloat (i.e. ios_base::fixed | ios_base:: scientific) where no precision is specified in the format string it passes, so this is actually conformant.

@jakeegan jakeegan restored the print_hex branch June 14, 2024 18:14
@jakeegan jakeegan reopened this Jun 14, 2024
@ldionne
Copy link
Member

ldionne commented Sep 10, 2024

Gentle ping on this. Do we want to move forward with this in some form? If not, let's close to clear the queue.

@jakeegan
Copy link
Member Author

Updated to use macros to test instead

@ldionne ldionne merged commit e99755d into llvm:main Sep 16, 2024
61 checks passed
@jakeegan jakeegan deleted the print_hex branch September 17, 2024 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants