hiddenid01 / redis

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

zset formatting returning incorrect score #414

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. zadd scores 99999999999999999 3
2. zrevrange scores 0 -1 WITHSCORES

What is the expected output? What do you see instead?
Expected:
1. "3"
2. "99999999999999999"
Result:
1. "3"
2. "1e+17"

What version of the product are you using? On what operating system?
2.04
Mac OS X

Please provide any additional information below.

I believe the problem lies here.
static void addReplyDouble(redisClient *c, double d) {
    char buf[128];

    snprintf(buf,sizeof(buf),"%.17g",d);
    addReplySds(c,sdscatprintf(sdsempty(),"$%lu\r\n%s\r\n",
        (unsigned long) strlen(buf),buf));
}

While g format is a nicety, I'd like to see the real value until it's too big 
to be stored.

Original issue reported on code.google.com by ashleym1...@gmail.com on 21 Dec 2010 at 7:59

GoogleCodeExporter commented 9 years ago
The expected value 99999999999999999 can never be returned, because there is a 
loss of precision in this value when converting to IEEE double.

Original comment by jacob.la...@gmail.com on 6 Jan 2011 at 12:39

GoogleCodeExporter commented 9 years ago
Crap. I was afraid of that. So just to be clear this is expected.

redis> zadd scores 9999 4
(integer) 1
redis> zadd scores 99999 5
(integer) 1
redis> zadd scores 999999 6
(integer) 1
redis> zadd scores 9999999 7
(integer) 1
redis> zadd scores 99999999 8
(integer) 1
redis> zadd scores 999999999 9
(integer) 1
redis> zadd scores 9999999999 10
(integer) 1
redis> zadd scores 99999999999 11
(integer) 1
redis> zadd scores 999999999999 12
(integer) 1
redis> zadd scores 9999999999999 13
(integer) 1
redis> zadd scores 99999999999999 14
(integer) 1
redis> zadd scores 999999999999999 15
(integer) 1
redis> zadd scores 9999999999999999 16
(integer) 1
redis> zadd scores 99999999999999999 17
(integer) 1
redis> zadd scores 999999999999999999 18
(integer) 1
redis> zadd scores 9999999999999999999 19
(integer) 1
redis> zadd scores 99999999999999999999 20
(integer) 1
redis> zrevrange scores 0 -1 WITHSCORES
1. "20"
2. "1e+20"
3. "19"
4. "1e+19"
5. "18"
6. "1e+18"
7. "17"
8. "1e+17"
9. "16"
10. "10000000000000000"
11. "15"
12. "999999999999999"
13. "14"
14. "99999999999999"
15. "13"
16. "9999999999999"
17. "12"
18. "999999999999"
19. "11"
20. "99999999999"
21. "10"
22. "9999999999"
23. "9"
24. "999999999"
25. "8"
26. "99999999"
27. "7"
28. "9999999"
29. "6"
30. "999999"
31. "5"
32. "99999"
33. "4"
34. "9999"

Original comment by ashleym1...@gmail.com on 6 Jan 2011 at 6:37

GoogleCodeExporter commented 9 years ago
This might be related to #621 in some way. 

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