MCPcopy Create free account
hub / github.com/MikeLankamp/fpm / is_test_valid

Method is_test_valid

tests/output.cpp:42–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40{
41protected:
42 bool is_test_valid(const std::ios_base& stream, double value) const
43 {
44 const auto floatfield = stream.flags() & std::ios::floatfield;
45
46#if defined(__GLIBCXX__ )
47 // stdlibc++ seems to have a bug where it applies thousands grouping in hexadecimal mode,
48 // and---even worse---applies the grouping through the "0x" prefix. This produces
49 // interesting results such as "0,x1.8p+3" instead of "0x1.8p+3" with a grouping
50 // of "\002", or "0,x,1.8p+3" with a grouping of "\001".
51 const auto& numpunct = std::use_facet<std::numpunct<char>>(stream.getloc());
52 if (floatfield == (std::ios::fixed | std::ios::scientific) && !numpunct.grouping().empty())
53 {
54 return false;
55 }
56#elif defined(_MSC_VER)
57 // Microsoft Visual C++ has a few problems:
58 // It doesn't properly ignore the specified precision for hexfloat
59 if (floatfield == (std::ios::fixed | std::ios::scientific))
60 {
61 return false;
62 }
63 // A precision of zero isn't properly handled with a floatfield of "auto" or scientific
64 if (stream.precision() == 0 && (floatfield == 0 || floatfield == std::ios::scientific))
65 {
66 return false;
67 }
68 // Specifying "showpoint" adds a spurious "0" when the value is 0.
69 if (value == 0 && (stream.flags() & std::ios::showpoint) != 0)
70 {
71 return false;
72 }
73#endif
74
75 return true;
76 }
77
78 void test(double value) const
79 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected