@@ -122,6 +122,13 @@ int unitTests()
122122 CHECK_EQUAL (tfm::format (" %E" , -1.23456E10 ), " -1.234560E+10" );
123123 CHECK_EQUAL (tfm::format (" %f" , -9.8765 ), " -9.876500" );
124124 CHECK_EQUAL (tfm::format (" %F" , 9.8765 ), " 9.876500" );
125+ # ifndef _MSC_VER
126+ CHECK_EQUAL (tfm::format (" %a" , -1.671111047267913818359375 ), " -0x1.abcdefp+0" );
127+ CHECK_EQUAL (tfm::format (" %A" , 1.671111047267913818359375 ), " 0X1.ABCDEFP+0" );
128+ # else
129+ CHECK_EQUAL (tfm::format (" %a" , -1.671111047267913818359375 ), " -0x1.abcdef0000000p+0" );
130+ CHECK_EQUAL (tfm::format (" %A" , 1.671111047267913818359375 ), " 0X1.ABCDEF0000000P+0" );
131+ # endif
125132 CHECK_EQUAL (tfm::format (" %g" , 10 ), " 10" );
126133 CHECK_EQUAL (tfm::format (" %G" , 100 ), " 100" );
127134 CHECK_EQUAL (tfm::format (" %c" , 65 ), " A" );
@@ -163,6 +170,16 @@ int unitTests()
163170 CHECK_EQUAL (tfm::format (" %.4d" , 10 ), " 0010" );
164171 CHECK_EQUAL (tfm::format (" %10.4f" , 1234.1234567890 ), " 1234.1235" );
165172 CHECK_EQUAL (tfm::format (" %.f" , 10.1 ), " 10" );
173+ // Per C++ spec, iostreams ignore the precision for "%a" to avoid precision
174+ // loss. This is a printf incompatibility.
175+ # ifndef _MSC_VER
176+ CHECK_EQUAL (tfm::format (" %.1a" , 1.13671875 ), " 0x1.23p+0" );
177+ CHECK_EQUAL (tfm::format (" %14a" , 1.671111047267913818359375 ), " 0x1.abcdefp+0" );
178+ # else
179+ // MSVC workaround
180+ CHECK_EQUAL (tfm::format (" %.1a" , 1.13671875 ), " 0x1.2300000000000p+0" );
181+ CHECK_EQUAL (tfm::format (" %21a" , 1.671111047267913818359375 ), " 0x1.abcdef0000000p+0" );
182+ # endif
166183 CHECK_EQUAL (tfm::format (" %.2s" , " asdf" ), " as" ); // strings truncate to precision
167184 CHECK_EQUAL (tfm::format (" %.2s" , std::string (" asdf" )), " as" );
168185 // Test variable precision & width
@@ -245,8 +262,6 @@ int unitTests()
245262
246263 // Unhandled C99 format spec
247264 EXPECT_ERROR ( tfm::format (" %n" , 10 ) )
248- EXPECT_ERROR ( tfm::format (" %a" , 10 ) )
249- EXPECT_ERROR ( tfm::format (" %A" , 10 ) )
250265
251266#ifdef TEST_WCHAR_T_COMPILE
252267 // Test wchar_t handling - should fail to compile!
0 commit comments