File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424#include < algorithm>
2525#include < iostream>
2626#include < locale>
27+ #include < limits>
28+ #include < iomanip>
2729#include < stdexcept>
2830#include < stack>
2931#include " utf_iterator.h"
@@ -324,7 +326,7 @@ namespace json {
324326 out<<" null" ;
325327 break ;
326328 case json::is_number:
327- out<<number ();
329+ out<<std::setprecision (std::numeric_limits< double >::digits10+ 1 )<< number ();
328330 break ;
329331 case json::is_string:
330332 out<<escape (str ());
Original file line number Diff line number Diff line change 1919#include < cppcms/json.h>
2020#include " test.h"
2121#include < iostream>
22+ #include < limits>
23+ #include < stdlib.h>
2224#include < sstream>
2325#include < iomanip>
2426using namespace cppcms ;
@@ -153,6 +155,21 @@ int main()
153155 v[" y" ][2 ]=json::array ();
154156 TEST (format (v)==" {\" x\" :10,\" y\" :[null,\" test\" ,[]]}" );
155157
158+ std::string fl=" 123456789123456789123456789123456789" ;
159+ fl = fl.substr (0 ,std::numeric_limits<double >::digits10);
160+ double big_int=atof (fl.c_str ());
161+ TEST (format (big_int)==fl);
162+ TEST (format (1277880000 )==" 1277880000" );
163+ TEST (format (-1277880000 )==" -1277880000" );
164+ TEST (atoi (format (std::numeric_limits<int >::max ()).c_str ()) == std::numeric_limits<int >::max ());
165+ TEST (atoi (format (std::numeric_limits<int >::min ()).c_str ()) == std::numeric_limits<int >::min ());
166+ std::string fl2=fl.substr (0 ,1 )+' .' +fl.substr (1 );
167+ big_int=atof (fl2.c_str ());
168+ TEST (format (big_int)==fl2);
169+ TEST (format (-big_int)==" -" + fl2);
170+ TEST (format (1.35e30 )==" 1.35e+30" );
171+ TEST (format (big_int * 1e30 ) == fl2+" e+30" );
172+
156173 }
157174 catch (std::exception const &e)
158175 {
You can’t perform that action at this time.
0 commit comments