File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3131#include " catch.hpp"
3232
3333#include < string.h>
34+ #include < sstream>
3435#include < math.h>
3536
3637namespace test {
@@ -1189,6 +1190,28 @@ TEST_CASE("float", "[]" ) {
11891190 // out of range for float: should switch to exp notation
11901191 test::sprintf (buffer, " %.1f" , 1E20 );
11911192 REQUIRE (!strcmp (buffer, " 1.0e+20" ));
1193+
1194+ // brute force float
1195+ bool fail = false ;
1196+ std::stringstream str;
1197+ str.precision (5 );
1198+ for (float i = -100000 ; i < 100000 ; i += 1 ) {
1199+ test::sprintf (buffer, " %.5f" , i / 10000 );
1200+ str.str (" " );
1201+ str << std::fixed << i / 10000 ;
1202+ fail = fail || !!strcmp (buffer, str.str ().c_str ());
1203+ }
1204+ REQUIRE (!fail);
1205+
1206+ // brute force exp
1207+ str.setf (std::ios::scientific, std::ios::floatfield);
1208+ for (float i = -1e20 ; i < 1e20 ; i += 1e15 ) {
1209+ test::sprintf (buffer, " %.5f" , i);
1210+ str.str (" " );
1211+ str << i;
1212+ fail = fail || !!strcmp (buffer, str.str ().c_str ());
1213+ }
1214+ REQUIRE (!fail);
11921215}
11931216
11941217
You can’t perform that action at this time.
0 commit comments