[postgis-devel] Proposal for sensible number output semantics

rmrodriguez at carto.com rmrodriguez at carto.com
Mon Jul 20 09:30:27 PDT 2020


Hi,

I think I finally have a proper solution to what I proposed. The PR is
in https://github.com/postgis/postgis/pull/570. The summary of the
changes:

* Use the shortest representation (enough to guarantee roundtrip).
* Uses scientific notation for absolute numbers smaller than 1e-8. The
previous behaviour was to output 0 for absolute values smaller than
1e-12 and fixed notation for anything bigger than that.
* Uses scientific notation for absolute numbers greater than 1e+15
(same behaviour).
* The precision parameter now also affects the scientific notation
(before it was fixed [5-8]).
* All output functions now respect the requested precision (without any limits).
* The default precision is the same (9 for GeoJSON, 15 for everything else).

Any comments are welcome!

On Mon, Apr 20, 2020 at 6:12 PM <rmrodriguez at carto.com> wrote:
>
> There is still quite a bit of testing to be done, but I have a initial
> implementation here:
> https://github.com/Algunenano/postgis/tree/shortest, with some tests
> in https://github.com/Algunenano/postgis/blob/3e2326976e349e38d94cc05a28c204d54205011e/liblwgeom/cunit/cu_print.c#L269
>
> Since I've had to write a new function in ryu (to_chars_fixed_point) I
> expect some errors to show up during testing (specially around the
> rounding or the handling of leading decimal zeros) and I still have to
> bring some of the optimizations to that code (fast print for integers
> for example).
> Once things are more tested, I'll clear the commits and make more
> clear what are the changes done to Ryu's d2s.c (which is a new file
> I've introduced from the upstream tree).
>
> Any comment or suggestions are more than welcome!
>
> On Mon, Apr 20, 2020 at 3:11 PM <rmrodriguez at carto.com> wrote:
> >
> > > Can you provide a set of examples (AKA unit tests)?  Then we can all see how it works.
> >
> > Yes, the idea is to have unit tests for lwprint_double to control and
> > showcase how the shortest representation works and the impact /
> > rounding due to the precision parameter.
> >
> > --
> > Raúl Marín Rodríguez
> > carto.com
>
>
>
> --
> Raúl Marín Rodríguez
> carto.com



-- 
Raúl Marín Rodríguez
carto.com


More information about the postgis-devel mailing list