michaelwittig / node-q

Q interfacing with Node.js
MIT License
52 stars 14 forks source link

Precision error on real (explicit) type: #40

Closed jacobloveless closed 5 years ago

jacobloveless commented 5 years ago

It looks to me like something is off on the encoding of a real ... A simple usecase:

var nodeq = require("node-q");
nodeq.connect({host: "localhost", port: 5000}, function(err, con) {
    con.k("", nodeq.real(1.2345),function(err, res){
        console.log(res)
    });
    });

Returns

>node t.js
1.2345000505447388
michaelwittig commented 5 years ago

I just tried:

var nodeq = require("node-q");
nodeq.connect({host: "localhost", port: 5000}, function(err, con) {
    con.k("show", nodeq.real(1.2345),function(err, res){
        console.log(res)
    });
});

You will see a 1.2345e in your q process.

I'm not sure if this is an issue or not... what are you try to achieve? only display the numbers?

jacobloveless commented 5 years ago

Sorry Michael, that was a bit unclear. My question was about precision (on the JavaScript side). A better example is below:

var nodeq = require("node-q");
nodeq.connect({host: "localhost", port: 5000}, function(err, con) {
    con.k("{`e set x;x}",nodeq.real(1.2345),function(err, res){
        console.log(res)
    });
    });

When I run this I get back a few trailing bits on the number (rather than padding with zeros)

node t.JS
1.2345000505447388

But I realize now this is actually the correct representation on the q side as well

q)\P 9999
q)e
1.2345000505447388e

So this is indeed not a bug , although for the life of me I'm not sure why these resolve to the numbers they do

michaelwittig commented 5 years ago

I gues that‘s the nature of floats.