Giter VIP home page Giter VIP logo

Comments (6)

evanhuang8 avatar evanhuang8 commented on June 15, 2024 1

@dvirsky I agree. The flag for serialization seems to be wrong at this line:

https://github.com/RedisLabsModules/rejson/blob/master/src/json_object.c#L342

I did some experiment for the flags:

(check out this snippet: https://repl.it/GjP1/0)

#include <stdio.h>
#include <math.h>
#include <float.h>

int main ()
{
   float a = 1.333333;
  
   printf("Should be: %lf, but losing precision: %g", a, a);
   
   return(0);
}

Output of the above is:

Should be: 1.333333, but losing precision: 1.33333 

Supposedly %g outputs the shorter of %e or %f, which in this case it uses %f and loses precision. See a similar issue here:

json-c/json-c#59

I get the need to save space for serialization, but in this case it should either do more detection in terms of precision or use %f outright.

from redisjson.

dvirsky avatar dvirsky commented on June 15, 2024

@itamarhaber I think it's a serialization issue, internally we shouldn't be losing precision

from redisjson.

evanhuang8 avatar evanhuang8 commented on June 15, 2024

And changing %e to %lf fixes the problem:

127.0.0.1:6380[7]> JSON.GET world
"1.333333"

Not sure about the implication in terms of the memory footprint, however.

from redisjson.

dvirsky avatar dvirsky commented on June 15, 2024

It shouldn't matter in terms of memory since this is only done when serializing the objects. Maybe make a PR and we'll continue the discussion over there?

from redisjson.

evanhuang8 avatar evanhuang8 commented on June 15, 2024

Here you go.

from redisjson.

evanhuang8 avatar evanhuang8 commented on June 15, 2024

Apparently, %.17g is the more correct version:

http://stackoverflow.com/questions/16839658/printf-width-specifier-to-maintain-precision-of-floating-point-value

from redisjson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.