chnaghong1990 / redis

Automatically exported from code.google.com/p/redis
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

ZADD is munging my score #621

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What version of Redis you are using, in what kind of Operating System?
2.2.11

What is the problem you are experiencing?
when I perform a ZADD with a score like: 20110802.4 the actual score written to 
redis is: 20110802.399999999

What steps will reproduce the problem?
def post_error(r, priority, msg):
    guid = str(uuid.uuid1())
    id = ekey(priority, guid)
    d = time.strftime('%Y%m%d',time.gmtime())
    score = skey(d, str(r.hincrby('log_event_scores', d, 1)))
    print score
    p = r.pipeline(transaction=True)
    p.set(id, msg)
    #p.zadd(pkey(priority), score, id )
    p.zadd(pkey(priority), id, score )
    p.execute()

Do you have an INFO output? Please past it here.

If it is a crash, can you please paste the stack trace that you can find in
the log file or on standard output? This is really useful for us!

Please provide any additional information below.

Original issue reported on code.google.com by rich...@bucker.net on 2 Aug 2011 at 3:43

GoogleCodeExporter commented 8 years ago
looks like it might be related to #414 in the use of double precision 
scanning/formatting.

Original comment by rich...@bucker.net on 2 Aug 2011 at 3:47

GoogleCodeExporter commented 8 years ago
It's sort of related.

In the case you offer, it's not that you are losing precision, it's that .4 can 
not be represented exactly in binary (though 1.4 and .4 have differing 
representations to the right of the decimal: 1.3999999999999999 and 
0.40000000000000002 respectively). Your computer does it's best to represent 
those values, but when formatting as base-10, it shows you really what it is 
storing (as best it can). There are ways of showing you a "prettier" 
representation of what it stored in such a way that you are less confused 
(http://babbage.cs.qc.edu/IEEE-754/Decimal.html does as much), but those aren't 
typically included as part of number formatting.

Regardless, both 20110802.399999999 and 20110802.4 are the same number in IEEE 
754 FP double representation, even if it isn't pretty.

Original comment by josiah.c...@gmail.com on 2 Aug 2011 at 6:19

GoogleCodeExporter commented 8 years ago
I accept the explanation.   but since I need the score to be entered by a 
human. I need the score to be pretty. 

Feel free to close the ticket or make it low priority. 

/r

Original comment by rich...@bucker.net on 2 Aug 2011 at 6:55

GoogleCodeExporter commented 8 years ago
Has there been any progress on this issue?  I can confirm that the issue is 
still present.  

Original comment by earl.oli...@gmail.com on 6 Mar 2014 at 9:13

GoogleCodeExporter commented 8 years ago
This Google Code project is outdated. Please file issues at the github 
repository: https://github.com/antirez/redis.

With regard to this issue: There's no need for any progress. Scores are stored 
as IEEE 754 floats as Josiah explained,  so it's not a real issue anyway.

Original comment by jeredi...@gmail.com on 6 Mar 2014 at 9:57

GoogleCodeExporter commented 8 years ago
This isn't a bug with Redis, it's a bug with your understanding of how floating 
point values work. Read https://code.google.com/p/redis/issues/detail?id=621#c2 
.

Original comment by josiah.c...@gmail.com on 6 Mar 2014 at 4:06