hermann on Thu, 18 Jan 2024 23:09:54 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

print() does output numbers in scientific notation violating JSON number spec


From latest JSON rfc:

https://www.rfc-editor.org/rfc/rfc8259#section-6

      number = [ minus ] int [ frac ] [ exp ]

      decimal-point = %x2E       ; .

      digit1-9 = %x31-39         ; 1-9

      e = %x65 / %x45            ; e E

      exp = e [ minus / plus ] 1*DIGIT

      frac = decimal-point 1*DIGIT

So no space is allowed between "frac" part end "exp" part.

But gp does output a space:

? version
%2 = [2, 15, 4]
? print(0.00001)
1.0000000000000000000000000000000000000 E-5
?

I use PARI/GP to write a JSON file, that is read by JavaScript/nodejs.
And that errors out on reading above number.
If I manually remove the space, "1.0000000000000000000000000000000000000E-5" can be processed easily.

I would say this is at least an interoperability bug.
It should be fixed, if there is not a really good reason to output that space.


Is there an option to make PARI/GP produce "0.00001" as output instead of scientific representation?


Regards,

Hermann.