Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loss of precision when formatting number #78

Closed
markddrake opened this issue Aug 7, 2024 · 3 comments
Closed

Loss of precision when formatting number #78

markddrake opened this issue Aug 7, 2024 · 3 comments
Labels
probably fixed? the issue/feature appears to be fixed/implemented, but there still may be issues

Comments

@markddrake
Copy link

{"systemInformation":{"yadamuVersion":"3.0","date":"2024-08-07T01:49:47.278Z","timeZoneOffset":420,"schema":"t_postgres","dbiKey":"postgres","vendor":"Postgres","dbVersion":"160001","softwareVendor":"The PostgreSQL Global Development Group","driverSettings":{"spatialFormat":"EWKB","timestampPrecision":6,"circleFormat":"CIRCLE"},"nodeClient":{"version":"v20.7.0","architecture":"x64","platform":"win32"},"currentUser":"postgres","sessionUser":"postgres","dbName":"yadamu","databaseVersion":"160001","timezone":"+00:00","postgisInfo":"3.4 USE_GEOS=1 USE_PROJ=1 USE_STATS=1","yadamuInstanceID":"5F0997C3-8D35-484C-9330-7D40370A6D39","yadamuInstallationTimestamp":"2024-08-02T21:06:18+00:00"},"ddl":[],"metadata":{"t1":{"tableSchema":"t_postgres","tableName":"t1","columnNames":["key","val"],"dataTypes":["smallint","double precision"],"sizeConstraints":[[16,0],[53]],"vendor":"Postgres"}},"data":{"t1":[[1,-1.7976931348623157e+308],[2,1.7976931348623157e+308],[26,-1.7976931348623157e+308],[27,1.7976931348623157e+308]]}}

Becomes

{
    "systemInformation": {
        "yadamuVersion": "3.0",
        "date": "2024-08-07T01:49:47.278Z",
        "timeZoneOffset": 420,
        "schema": "t_postgres",
        "dbiKey": "postgres",
        "vendor": "Postgres",
        "dbVersion": "160001",
        "softwareVendor": "The PostgreSQL Global Development Group",
        "driverSettings": {
            "spatialFormat": "EWKB",
            "timestampPrecision": 6,
            "circleFormat": "CIRCLE"
        },
        "nodeClient": {
            "version": "v20.7.0",
            "architecture": "x64",
            "platform": "win32"
        },
        "currentUser": "postgres",
        "sessionUser": "postgres",
        "dbName": "yadamu",
        "databaseVersion": "160001",
        "timezone": "+00:00",
        "postgisInfo": "3.4 USE_GEOS=1 USE_PROJ=1 USE_STATS=1",
        "yadamuInstanceID": "5F0997C3-8D35-484C-9330-7D40370A6D39",
        "yadamuInstallationTimestamp": "2024-08-02T21:06:18+00:00"
    },
    "ddl": [
    ],
    "metadata": {
        "t1": {
            "tableSchema": "t_postgres",
            "tableName": "t1",
            "columnNames": [
                "key",
                "val"
            ],
            "dataTypes": [
                "smallint",
                "double precision"
            ],
            "sizeConstraints": [
                [
                    16,
                    0
                ],
                [
                    53
                ]
            ],
            "vendor": "Postgres"
        }
    },
    "data": {
        "t1": [
            [
                1,
                -1.79769313486232E+308
            ],
            [
                2,
                1.79769313486232E+308
            ],
            [
                26,
                -1.79769313486232E+308
            ],
            [
                27,
                1.79769313486232E+308
            ]
        ]
    }
}

Does not happen with JSON_VIEWER plugin

{
	"systemInformation": {
		"yadamuVersion": "3.0",
		"date": "2024-08-07T01:49:47.278Z",
		"timeZoneOffset": 420,
		"schema": "t_postgres",
		"dbiKey": "postgres",
		"vendor": "Postgres",
		"dbVersion": "160001",
		"softwareVendor": "The PostgreSQL Global Development Group",
		"driverSettings": {
			"spatialFormat": "EWKB",
			"timestampPrecision": 6,
			"circleFormat": "CIRCLE"
		},
		"nodeClient": {
			"version": "v20.7.0",
			"architecture": "x64",
			"platform": "win32"
		},
		"currentUser": "postgres",
		"sessionUser": "postgres",
		"dbName": "yadamu",
		"databaseVersion": "160001",
		"timezone": "+00:00",
		"postgisInfo": "3.4 USE_GEOS=1 USE_PROJ=1 USE_STATS=1",
		"yadamuInstanceID": "5F0997C3-8D35-484C-9330-7D40370A6D39",
		"yadamuInstallationTimestamp": "2024-08-02T21:06:18+00:00"
	},
	"ddl": [],
	"metadata": {
		"t1": {
			"tableSchema": "t_postgres",
			"tableName": "t1",
			"columnNames": [
				"key",
				"val"
			],
			"dataTypes": [
				"smallint",
				"double precision"
			],
			"sizeConstraints": [
				[
					16,
					0
				],
				[
					53
				]
			],
			"vendor": "Postgres"
		}
	},
	"data": {
		"t1": [
			[
				1,
				-1.7976931348623157e308
			],
			[
				2,
				1.7976931348623157e308
			],
			[
				26,
				-1.7976931348623157e308
			],
			[
				27,
				1.7976931348623157e308
			]
		]
	}
}
@molsonkiko
Copy link
Owner

@markddrake

Hmmm, unfortunately I can replicate this bug with the latest version of JsonTools. Thanks for bringing it to my attention.

This appears to be a known issue with the way C# formats double-precision floating point numbers (which I use to represent the number type in JSON). I'm not yet sure how I'm going to fix this bug, but I will make sure to include a fix in version 8.1 of JsonTools.

molsonkiko added a commit that referenced this issue Aug 9, 2024
previously the string representation of doubles was unnecessarily low-precision,
    causing loss of data as described in #78
Unfortunately, this means that some numbers with multiple equally valid representations
    (for example, 2.2 could be represented as "2.2" or "2.2000000000000002")
    will now be represented in the longest way.

Also add RandomStringFromRegex, although this has not yet been fully implemented or incorporated into any external code.
@molsonkiko
Copy link
Owner

This issue should be resolved by this commit.

Again, sorry for not recognizing this issue sooner. I plan to release version 8.1 on the Plugins Manager fairly soon, and that version will include this fix.

@molsonkiko molsonkiko added the probably fixed? the issue/feature appears to be fixed/implemented, but there still may be issues label Aug 9, 2024
@molsonkiko
Copy link
Owner

The fix to this issue is now in v8.1, which I will try to get listed in the Notepad++ Plugin List ASAP.

Once the next version of Notepad++ is released that lists that version of JsonTools, I will wait a little while and then close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
probably fixed? the issue/feature appears to be fixed/implemented, but there still may be issues
Projects
None yet
Development

No branches or pull requests

2 participants