Thread: [Cppcms-users] JSON integer conversion(s)
Brought to you by:
artyom-beilis
From: Geert V. de V. <gee...@ba...> - 2010-06-30 08:26:06
|
Hi, I have noticed that the conversion of C++ integer numbers to json goes trough converting it to a double. This can get undesired behavior for large numbers when it automatic adds exponents when outputting it as json. eg. int uid = 1277880000; results into this: { "uid":1.27788e+09 } I want to keep the integer representation. If I want a double representation I will convert it myself explicitly. If possible by adding the function "void value::number(long int x);" this issue can be solved. It would also be useful to add conversion functions for unsigned integers. Greetings DISCLAIMER: Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you. |
From: Artyom <art...@ya...> - 2010-06-30 10:02:16
|
Hello, Thanks for the good point you bring. Actually not only integer number were not printed correctly, but floating point ones as well. I fixed this that numbers are printed with maximal possible precision and this should solve problem (I also added test case for such numbers) So your example generates 1277880000 string and not 1.27788e+09 (changeset 1298, you can take if from SVN) > > I have noticed that the conversion of C++ integer numbers to json goes > trough converting it to a double. This can get undesired behavior for > large numbers when it automatic adds exponents when outputting it as > json. Double is capable representing integer numbers correctly, so the problem is not in converting them to double but rather in printing them. > > I want to keep the integer representation. If I want a double > representation I will convert it myself explicitly. > If possible by adding the function "void value::number(long int x);" > this issue can be solved. > This is not correct solution as neither JSON nor JavaScript have no integer or double type they have number type. So introducing "integer" type would be incorrect solution as it extends JSON object representation. IEEE floating point number can handle integer values correctly (with correct rounding and precision) so there no need to change internal representation. Also if you need real UUIDs neither integer nor double (and not even 64 bit integer) would be good enough. You should probably use string. Thanks for the report, Regards, Artyom |
From: Hermann S. <of...@he...> - 2010-06-30 11:16:45
|
Using changeset 1298 together with Visual Studio 2008 creates the following test error: The following tests FAILED: 4 - json_test (Failed) Bye, Hermann > Hello, > > Thanks for the good point you bring. > > Actually not only integer number were not printed correctly, but floating point > ones as well. > I fixed this that numbers are printed with maximal possible precision and this > should solve problem > (I also added test case for such numbers) > > So your example generates 1277880000 string and not 1.27788e+09 > > (changeset 1298, you can take if from SVN) > > > >> I have noticed that the conversion of C++ integer numbers to json goes >> trough converting it to a double. This can get undesired behavior for >> large numbers when it automatic adds exponents when outputting it as >> json. > > Double is capable representing integer numbers correctly, so the problem is not > in converting > them to double but rather in printing them. > >> I want to keep the integer representation. If I want a double >> representation I will convert it myself explicitly. >> If possible by adding the function "void value::number(long int x);" >> this issue can be solved. >> > > This is not correct solution as neither JSON nor JavaScript have no integer or > double type they > have number type. So introducing "integer" type would be incorrect solution as > it extends JSON object > representation. > > IEEE floating point number can handle integer values correctly (with correct > rounding and precision) > so there no need to change internal representation. > > Also if you need real UUIDs neither integer nor double (and not even 64 bit > integer) would be good enough. > You should probably use string. > > > Thanks for the report, > Regards, > Artyom > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
From: Artyom <art...@ya...> - 2010-06-30 11:21:42
|
Can you run svn update (get 1299) and rebuild once more and give me the output of ./json_test So I'll be able to fix the problem, (till I get to MSVC to debug the problem) Artyom ----- Original Message ---- > From: Hermann Seib <of...@he...> > To: cpp...@li... > Sent: Wed, June 30, 2010 2:01:10 PM > Subject: Re: [Cppcms-users] JSON integer conversion(s) > > Using changeset 1298 together with Visual Studio 2008 creates the > following test error: > > The following tests FAILED: > 4 - json_test (Failed) > > Bye, > > Hermann > > > Hello, > > > > Thanks for the good point you bring. > > > > Actually not only integer number were not printed correctly, but floating >point > > > ones as well. > > I fixed this that numbers are printed with maximal possible precision and >this > > > should solve problem > > (I also added test case for such numbers) > > > > So your example generates 1277880000 string and not 1.27788e+09 > > > > (changeset 1298, you can take if from SVN) > > > > > > > >> I have noticed that the conversion of C++ integer numbers to json goes > >> trough converting it to a double. This can get undesired behavior for > >> large numbers when it automatic adds exponents when outputting it as > >> json. > > > > Double is capable representing integer numbers correctly, so the problem is >not > > > in converting > > them to double but rather in printing them. > > > >> I want to keep the integer representation. If I want a double > >> representation I will convert it myself explicitly. > >> If possible by adding the function "void value::number(long int x);" > >> this issue can be solved. > >> > > > > This is not correct solution as neither JSON nor JavaScript have no integer >or > > > double type they > > have number type. So introducing "integer" type would be incorrect solution >as > > > it extends JSON object > > representation. > > > > IEEE floating point number can handle integer values correctly (with correct > > > rounding and precision) > > so there no need to change internal representation. > > > > Also if you need real UUIDs neither integer nor double (and not even 64 bit > > integer) would be good enough. > > You should probably use string. > > > > > > Thanks for the report, > > Regards, > > Artyom > > > > > > > > > > >------------------------------------------------------------------------------ > > This SF.net email is sponsored by Sprint > > What will you do first with EVO, the first 4G phone? > > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > > _______________________________________________ > > Cppcms-users mailing list > > Cpp...@li... > > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Hermann S. <of...@he...> - 2010-06-30 11:58:31
|
> Can you run svn update (get 1299) and rebuild once more and give me the output > of ./json_test Failed:Error D:\Dev\CppCMS\tests\json_test.cpp:170 format(1.35e30)=="1.35e+30" Bye, Hermann |
From: Artyom <art...@ya...> - 2010-06-30 17:14:05
|
Thanks, Looks like I have to get to MSVC to solve this issue, but it does not look critical. Opened a bug: https://sourceforge.net/tracker/?func=detail&aid=3023329&group_id=209965&atid=1011835 Artyom ----- Original Message ---- > From: Hermann Seib <of...@he...> > To: cpp...@li... > Sent: Wed, June 30, 2010 2:42:47 PM > Subject: Re: [Cppcms-users] JSON integer conversion(s) > > > Can you run svn update (get 1299) and rebuild once more and give me the >output > > of ./json_test > > Failed:Error D:\Dev\CppCMS\tests\json_test.cpp:170 > format(1.35e30)=="1.35e+30" > > Bye, > > Hermann > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Hermann S. <of...@he...> - 2010-07-01 07:53:04
|
If it helps you, here's what VC15 (i.e., Visual Studio 2008) generates: format(1.35e30)="1.35e+030" (note the additional 0). Bye, Hermann > Thanks, > > Looks like I have to get to MSVC to solve this issue, but it does not look > critical. > > Opened a bug: > https://sourceforge.net/tracker/?func=detail&aid=3023329&group_id=209965&atid=1011835 > > > Artyom > > > > > ----- Original Message ---- >> From: Hermann Seib <of...@he...> >> To: cpp...@li... >> Sent: Wed, June 30, 2010 2:42:47 PM >> Subject: Re: [Cppcms-users] JSON integer conversion(s) >> >>> Can you run svn update (get 1299) and rebuild once more and give me the >> output >>> of ./json_test >> Failed:Error D:\Dev\CppCMS\tests\json_test.cpp:170 >> format(1.35e30)=="1.35e+30" >> >> Bye, >> >> Hermann >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by Sprint >> What will you do first with EVO, the first 4G phone? >> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first >> _______________________________________________ >> Cppcms-users mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cppcms-users >> > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
From: Artyom <art...@ya...> - 2010-07-01 09:17:50
|
Thanks, I've committed changes 1301 that should deal with extra zeros. Hopefully it fixes this test fault. Artyom ----- Original Message ---- > From: Hermann Seib <of...@he...> > To: cpp...@li... > Sent: Thu, July 1, 2010 10:52:42 AM > Subject: Re: [Cppcms-users] JSON integer conversion(s) > > If it helps you, here's what VC15 (i.e., Visual Studio 2008) generates: > > format(1.35e30)="1.35e+030" (note the additional 0). > > Bye, > > Hermann > > > Thanks, > > > > Looks like I have to get to MSVC to solve this issue, but it does not look > > critical. > > > > Opened a bug: > > >https://sourceforge.net/tracker/?func=detail&aid=3023329&group_id=209965&atid=1011835 > > > > > > > Artyom > > > > > > > > > > ----- Original Message ---- > >> From: Hermann Seib <of...@he...> > >> To: cpp...@li... > >> Sent: Wed, June 30, 2010 2:42:47 PM > >> Subject: Re: [Cppcms-users] JSON integer conversion(s) > >> > >>> Can you run svn update (get 1299) and rebuild once more and give me the > >> output > >>> of ./json_test > >> Failed:Error D:\Dev\CppCMS\tests\json_test.cpp:170 > >> format(1.35e30)=="1.35e+30" > >> > >> Bye, > >> > >> Hermann > >> > >> >------------------------------------------------------------------------------ > >> This SF.net email is sponsored by Sprint > >> What will you do first with EVO, the first 4G phone? > >> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > >> _______________________________________________ > >> Cppcms-users mailing list > >> Cpp...@li... > >> https://lists.sourceforge.net/lists/listinfo/cppcms-users > >> > > > > > > > > > > >------------------------------------------------------------------------------ > > This SF.net email is sponsored by Sprint > > What will you do first with EVO, the first 4G phone? > > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > > _______________________________________________ > > Cppcms-users mailing list > > Cpp...@li... > > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Hermann S. <of...@he...> - 2010-07-01 09:50:54
|
Yes. Bye, Hermann > Thanks, > > I've committed changes 1301 that should deal with extra zeros. > Hopefully it fixes this test fault. > > Artyom > > > > > ----- Original Message ---- >> From: Hermann Seib <of...@he...> >> To: cpp...@li... >> Sent: Thu, July 1, 2010 10:52:42 AM >> Subject: Re: [Cppcms-users] JSON integer conversion(s) >> >> If it helps you, here's what VC15 (i.e., Visual Studio 2008) generates: >> >> format(1.35e30)="1.35e+030" (note the additional 0). >> >> Bye, >> >> Hermann >> >>> Thanks, >>> >>> Looks like I have to get to MSVC to solve this issue, but it does not look >>> critical. >>> >>> Opened a bug: >>> >> https://sourceforge.net/tracker/?func=detail&aid=3023329&group_id=209965&atid=1011835 >> >>> >>> Artyom >>> >>> >>> >>> >>> ----- Original Message ---- >>>> From: Hermann Seib <of...@he...> >>>> To: cpp...@li... >>>> Sent: Wed, June 30, 2010 2:42:47 PM >>>> Subject: Re: [Cppcms-users] JSON integer conversion(s) >>>> >>>>> Can you run svn update (get 1299) and rebuild once more and give me the >>>> output >>>>> of ./json_test >>>> Failed:Error D:\Dev\CppCMS\tests\json_test.cpp:170 >>>> format(1.35e30)=="1.35e+30" >>>> >>>> Bye, >>>> >>>> Hermann >>>> >>>> >> ------------------------------------------------------------------------------ >>>> This SF.net email is sponsored by Sprint >>>> What will you do first with EVO, the first 4G phone? >>>> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first >>>> _______________________________________________ >>>> Cppcms-users mailing list >>>> Cpp...@li... >>>> https://lists.sourceforge.net/lists/listinfo/cppcms-users >>>> >>> >>> >>> >>> >> ------------------------------------------------------------------------------ >>> This SF.net email is sponsored by Sprint >>> What will you do first with EVO, the first 4G phone? >>> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first >>> _______________________________________________ >>> Cppcms-users mailing list >>> Cpp...@li... >>> https://lists.sourceforge.net/lists/listinfo/cppcms-users >>> >>> >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by Sprint >> What will you do first with EVO, the first 4G phone? >> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first >> _______________________________________________ >> Cppcms-users mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cppcms-users >> > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
From: Artyom <art...@ya...> - 2010-06-30 11:19:12
|
> It would also be useful to add conversion functions for unsigned > integers. I also added specializations (traits) for all integer and floating point types so that you can access all values like get<unsigned>("x"). changeset 1299. Artyom |
From: Geert V. de V. <gee...@ba...> - 2010-06-30 12:34:12
|
Tnx for the quick update! On Wed, 2010-06-30 at 04:19 -0700, Artyom wrote: > > It would also be useful to add conversion functions for unsigned > > integers. > > I also added specializations (traits) for all integer and floating point types > so > that you can access all values like get<unsigned>("x"). > > changeset 1299. > > Artyom > > > DISCLAIMER: Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you. |