-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[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
Conversation
@llvm/pr-subscribers-libcxx Author: Jake Egan (jakeegan) ChangesThe test expects a hex float format of 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:
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]
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this 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."
Actually turns out the C++ standard has a specific carve-out for precision in the case of hexfloat (i.e. |
...cale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp
Outdated
Show resolved
Hide resolved
Gentle ping on this. Do we want to move forward with this in some form? If not, let's close to clear the queue. |
Updated to use macros to test instead |
The test expects a hex float format of
0x0p+0
, but AIX prints0x0.0p+0
. This change adjusts the test to accept both.