Jump to page: 1 2
Thread overview
std.json parsing real numbers.
Aug 08, 2013
khurshid
Aug 08, 2013
MrSmith
Aug 08, 2013
khurshid
Aug 08, 2013
Borislav Kosharov
Aug 08, 2013
Nick Sabalausky
Aug 08, 2013
Borislav Kosharov
Aug 08, 2013
Tofu Ninja
Aug 08, 2013
Ali Çehreli
Aug 08, 2013
Nick Sabalausky
Aug 10, 2013
H. S. Teoh
Aug 10, 2013
Borislav Kosharov
Aug 10, 2013
H. S. Teoh
Aug 10, 2013
H. S. Teoh
August 08, 2013
I just check  std.json for parsing real numbers.

import std.json;
import std.stdio: writeln;

int main()
{
	auto json = parseJSON("1        .24E          +1");
	writeln(toJSON(&json));
	return 0;
}

and
output:  12.4


It's bug or normal ?
August 08, 2013
On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
>
> I just check  std.json for parsing real numbers.
>
> import std.json;
> import std.stdio: writeln;
>
> int main()
> {
> 	auto json = parseJSON("1        .24E          +1");
> 	writeln(toJSON(&json));
> 	return 0;
> }
>
> and
> output:  12.4
>
>
> It's bug or normal ?

Yep, because 1.24E+1 is 12.4E0
August 08, 2013
On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
> On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
>>
>> I just check  std.json for parsing real numbers.
>>
>> import std.json;
>> import std.stdio: writeln;
>>
>> int main()
>> {
>> 	auto json = parseJSON("1        .24E          +1");
>> 	writeln(toJSON(&json));
>> 	return 0;
>> }
>>
>> and
>> output:  12.4
>>
>>
>> It's bug or normal ?
>
> Yep, because 1.24E+1 is 12.4E0

I wrote not a "1.24E+1", a "1     .24E     +1"  with leading spaces.
August 08, 2013
On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
>
> I just check  std.json for parsing real numbers.
>
> import std.json;
> import std.stdio: writeln;
>
> int main()
> {
> 	auto json = parseJSON("1        .24E          +1");
> 	writeln(toJSON(&json));
> 	return 0;
> }
>
> and
> output:  12.4
>
>
> It's bug or normal ?

As mentioned in a different thread, it's a bug since it doesn't adhere to the JSON standard.
August 08, 2013
On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
> On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
>> On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
>>>
>>> I just check  std.json for parsing real numbers.
>>>
>>> import std.json;
>>> import std.stdio: writeln;
>>>
>>> int main()
>>> {
>>> 	auto json = parseJSON("1        .24E          +1");
>>> 	writeln(toJSON(&json));
>>> 	return 0;
>>> }
>>>
>>> and
>>> output:  12.4
>>>
>>>
>>> It's bug or normal ?
>>
>> Yep, because 1.24E+1 is 12.4E0
>
> I wrote not a "1.24E+1", a "1     .24E     +1"  with leading spaces.

Well what should it be if it's not 12.4? If you think it should be 2.24 you are wrong. In JSON there are no additions or subtractions. It is only static data. It is just a format. And although JSON stands for JavaScriptObjectNotation it isn't JS. Even if {"key":1.24 + 1} is valid JS it is not valid JSON.
August 08, 2013
On Thu, 08 Aug 2013 17:20:16 +0200
"Borislav Kosharov" <bosak@gmail.com> wrote:

> On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
> > On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
> >> On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
> >>>
> >>> I just check  std.json for parsing real numbers.
> >>>
> >>> import std.json;
> >>> import std.stdio: writeln;
> >>>
> >>> int main()
> >>> {
> >>> 	auto json = parseJSON("1        .24E          +1");
> >>> 	writeln(toJSON(&json));
> >>> 	return 0;
> >>> }
> >>>
> >>> and
> >>> output:  12.4
> >>>
> >>>
> >>> It's bug or normal ?
> >>
> >> Yep, because 1.24E+1 is 12.4E0
> >
> > I wrote not a "1.24E+1", a "1     .24E     +1"  with leading spaces.
> 
> Well what should it be if it's not 12.4?

A syntax error.

August 08, 2013
On Thursday, 8 August 2013 at 16:05:56 UTC, Nick Sabalausky wrote:
> On Thu, 08 Aug 2013 17:20:16 +0200
> "Borislav Kosharov" <bosak@gmail.com> wrote:
>
>> On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
>> > On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
>> >> On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
>> >>>
>> >>> I just check  std.json for parsing real numbers.
>> >>>
>> >>> import std.json;
>> >>> import std.stdio: writeln;
>> >>>
>> >>> int main()
>> >>> {
>> >>> 	auto json = parseJSON("1        .24E          +1");
>> >>> 	writeln(toJSON(&json));
>> >>> 	return 0;
>> >>> }
>> >>>
>> >>> and
>> >>> output:  12.4
>> >>>
>> >>>
>> >>> It's bug or normal ?
>> >>
>> >> Yep, because 1.24E+1 is 12.4E0
>> >
>> > I wrote not a "1.24E+1", a "1     .24E     +1"  with leading spaces.
>> 
>> Well what should it be if it's not 12.4?
>
> A syntax error.

I don't think this would cause any problems. It would just throw syntax error because there is white-space between? It would be just annoying to get syntax error because of extra white-space.

Maybe this is one of the situations where we should think "It's not a bug, it's a feature!"

Unless there is a situation that would make no sense to work or something, it should be left like it is now.
August 08, 2013
On Thursday, 8 August 2013 at 18:46:17 UTC, Borislav Kosharov wrote:
> On Thursday, 8 August 2013 at 16:05:56 UTC, Nick Sabalausky wrote:
>> On Thu, 08 Aug 2013 17:20:16 +0200
>> "Borislav Kosharov" <bosak@gmail.com> wrote:
>>
>>> On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
>>> > On Thursday, 8 August 2013 at 10:11:07 UTC, MrSmith wrote:
>>> >> On Thursday, 8 August 2013 at 08:04:49 UTC, khurshid wrote:
>>> >>>
>>> >>> I just check  std.json for parsing real numbers.
>>> >>>
>>> >>> import std.json;
>>> >>> import std.stdio: writeln;
>>> >>>
>>> >>> int main()
>>> >>> {
>>> >>> 	auto json = parseJSON("1        .24E          +1");
>>> >>> 	writeln(toJSON(&json));
>>> >>> 	return 0;
>>> >>> }
>>> >>>
>>> >>> and
>>> >>> output:  12.4
>>> >>>
>>> >>>
>>> >>> It's bug or normal ?
>>> >>
>>> >> Yep, because 1.24E+1 is 12.4E0
>>> >
>>> > I wrote not a "1.24E+1", a "1     .24E     +1"  with leading spaces.
>>> 
>>> Well what should it be if it's not 12.4?
>>
>> A syntax error.
>
> I don't think this would cause any problems. It would just throw syntax error because there is white-space between? It would be just annoying to get syntax error because of extra white-space.
>
> Maybe this is one of the situations where we should think "It's not a bug, it's a feature!"
>
> Unless there is a situation that would make no sense to work or something, it should be left like it is now.

Its not really a situation where we should deviate from the specs... it is starting to seem that the json specs say that there should be no white spaces and as this is a standard lib, we should conform to that
August 08, 2013
On 08/08/2013 11:46 AM, Borislav Kosharov wrote:
>>> > I wrote not a "1.24E+1", a "1     .24E     +1"  with leading > spaces.
>>>
>>> Well what should it be if it's not 12.4?
>>
>> A syntax error.
>
> I don't think this would cause any problems. It would just throw syntax
> error because there is white-space between? It would be just annoying to
> get syntax error because of extra white-space.
>
> Maybe this is one of the situations where we should think "It's not a
> bug, it's a feature!"
>
> Unless there is a situation that would make no sense to work or
> something, it should be left like it is now.

How about integers? I wouldn't expect "4 2" to be parsed silently as 42.

Ali

August 08, 2013
On Thu, 08 Aug 2013 20:46:15 +0200
"Borislav Kosharov" <boby_dsm@abv.bg> wrote:

> On Thursday, 8 August 2013 at 16:05:56 UTC, Nick Sabalausky wrote:
> > On Thu, 08 Aug 2013 17:20:16 +0200
> > "Borislav Kosharov" <bosak@gmail.com> wrote:
> >
> >> On Thursday, 8 August 2013 at 10:13:51 UTC, khurshid wrote:
> >> >
> >> > I wrote not a "1.24E+1", a "1     .24E     +1"  with leading spaces.
> >> 
> >> Well what should it be if it's not 12.4?
> >
> > A syntax error.
> 
> I don't think this would cause any problems. It would just throw syntax error because there is white-space between? It would be just annoying to get syntax error because of extra white-space.
> 
> Maybe this is one of the situations where we should think "It's not a bug, it's a feature!"
> 
> Unless there is a situation that would make no sense to work or something, it should be left like it is now.

Specs should be adhered to strictly. Otherwise you can wind up in the "antirobustness principle" situation like late 90's HTML. Laxness begets more laxness...and then incompatibility bugs.

« First   ‹ Prev
1 2