Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mwtoews
Copy link
Contributor

@mwtoews mwtoews commented Oct 16, 2023

This PR modifies how big and small values are formatted by WKTWriter by switching from positional to scientific notation where necessary, to avoid rounding to zero or overflowing a char buffer crash.

This somewhat expands the "trim" mode definition to mean "print pretty numbers" since it doesn't always honour (e.g.) "3" to show fixed millimetre precision, since it will use scientific notation to show smaller non-zero numbers if necessary. The non-trim mode still uses fixed notation, and will show (e.g.) "-0" in some cases.

Also the char buffer used for these numbers is reduced from 128 to 28.

Some new unit tests are added for GEOS_printDouble from the CAPI. Other unit tests check outputs with trim set on/off.

Closes #970


Some [unpractical] geometries mapped in SI meters:

  1. Classical electron radius: ./bin/geosop -a "point(0 0)" buffer 2.8179403227e-15

POLYGON ((2.8179403227e-15 0, 2.763794389558889e-15 -5.497528849777754e-16, 2.6034373879807804e-15 -1.0783790748908248e-15, 2.3430317476070782e-15 -1.5655637617177719e-15, 1.992584711160178e-15 -1.9925847111601778e-15, 1.5655637617177723e-15 -2.3430317476070782e-15, 1.078379074890825e-15 -2.6034373879807804e-15, 5.497528849777756e-16 -2.763794389558889e-15, 1.7254907981914074e-31 -2.8179403227e-15, -5.497528849777752e-16 -2.763794389558889e-15, -1.0783790748908246e-15 -2.6034373879807804e-15, -1.5655637617177713e-15 -2.343031747607079e-15, -1.9925847111601778e-15 -1.992584711160178e-15, -2.3430317476070786e-15 -1.5655637617177719e-15, -2.6034373879807804e-15 -1.078379074890825e-15, -2.763794389558889e-15 -5.497528849777764e-16, -2.8179403227e-15 -3.4509815963828148e-31, -2.763794389558889e-15 5.497528849777757e-16, -2.6034373879807808e-15 1.0783790748908244e-15, -2.343031747607079e-15 1.5655637617177713e-15, -1.9925847111601786e-15 1.9925847111601778e-15, -1.5655637617177719e-15 2.3430317476070782e-15, -1.0783790748908263e-15 2.60343738798078e-15, -5.497528849777765e-16 2.763794389558889e-15, -5.176472394574221e-31 2.8179403227e-15, 5.497528849777755e-16 2.763794389558889e-15, 1.0783790748908253e-15 2.6034373879807804e-15, 1.5655637617177711e-15 2.343031747607079e-15, 1.9925847111601774e-15 1.9925847111601786e-15, 2.3430317476070782e-15 1.5655637617177719e-15, 2.60343738798078e-15 1.0783790748908265e-15, 2.763794389558889e-15 5.497528849777767e-16, 2.8179403227e-15 0))

  1. Observable universe: ./bin/geosop -a "point(0 0)" buffer 4.40e26

POLYGON ((4.4e+26 0, 4.315455233774214e+26 -8.583974168709644e+25, 4.0650699430496615e+26 -1.683807102406395e+26, 3.658466294131199e+26 -2.4445090252862496e+26, 3.111269837220809e+26 -3.111269837220809e+26, 2.4445090252862503e+26 -3.658466294131199e+26, 1.683807102406395e+26 -4.0650699430496615e+26, 8.583974168709647e+25 -4.315455233774214e+26, 26942229581.24177 -4.4e+26, -8.58397416870964e+25 -4.315455233774214e+26, -1.6838071024063948e+26 -4.0650699430496615e+26, -2.4445090252862486e+26 -3.6584662941312e+26, -3.111269837220809e+26 -3.111269837220809e+26, -3.6584662941312e+26 -2.4445090252862496e+26, -4.0650699430496615e+26 -1.6838071024063955e+26, -4.315455233774214e+26 -8.583974168709659e+25, -4.4e+26 -53884459162.48354, -4.315455233774214e+26 8.583974168709649e+25, -4.065069943049662e+26 1.6838071024063945e+26, -3.6584662941312e+26 2.4445090252862486e+26, -3.11126983722081e+26 3.111269837220809e+26, -2.4445090252862496e+26 3.658466294131199e+26, -1.6838071024063976e+26 4.065069943049661e+26, -8.58397416870966e+25 4.3154552337742135e+26, -80826688743.72531 4.4e+26, 8.583974168709645e+25 4.315455233774214e+26, 1.6838071024063962e+26 4.0650699430496615e+26, 2.4445090252862482e+26 3.6584662941312e+26, 3.1112698372208085e+26 3.11126983722081e+26, 3.658466294131199e+26 2.4445090252862496e+26, 4.065069943049661e+26 1.683807102406398e+26, 4.3154552337742135e+26 8.583974168709664e+25, 4.4e+26 0))

  1. The finite extremes of double-precision: ./bin/geosop -a "point(5e-324 1.7e308)"

POINT (5e-324 1.7e+308)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash on large but finite floats on macOS

1 participant