Repository navigation
Closed
Description
Hi,
Has data like this:
1) "\x03)\r\xeb\x01\x80\n\x83:\x006D\x92:"
2) "1.9614519504605786e-293"
3) "\x03(\xd7\xb1\x00\x80\n\x81:\x00\x00\r\xdc:\x06N\xf75:\x006D\x92:"
4) "1.944868821887621e-293"
5) "\x03(\xc0\xd5J\x00\ny:\xb7\xc5%\xd5:"
6) "1.9378784977317831e-293"
7) "\x03 \xdcZ\xd6\x00\n\x14:i\xa41*:"
8) "1.3199923365196986e-293"
9) "\x03\x1cp\x91\x16\x80\t\xec:\x06N\xf75:"
10) "1.1132416933007594e-293"
11) "\x03\x1b\xe0\n\xef\x80\t\xe8:4YE\xfe:\x006D\x92:"
12) "1.0911431143988315e-293"
13) "\x03\x1b\xdf:]\x80\t\xe6:\x006D\x92:"
14) "1.0910185377047153e-293"
15) "\x03\x1b\xddw\xc5\x00\t\xe4:\x006D\x92:"
16) "1.0907494019758316e-293"
17) "\x03\x16\xf0\x9fv\x00\t\xe1:\x00\x01}W:\x006D\x92:"
18) "8.9795875511162971e-294"
19) "\x03\x16\xc9\xc1\xfc\x80\t\xdb"
20) "8.920160461988921e-294"
21) "\x03\x16\x81\x9aZ\x80\t\xc8"
22) "8.8098314835680527e-294"
23) "\x03\a\xbe\xeb\x02\x80\tr"
24) "4.6475124864639765e-294"
25) "\x03\x05F\xb5M\x80\tH"
26) "4.1641694138777194e-294"
27) "\x03\x05:&%\x80\tC"
28) "4.1545675311387456e-294"
29) "\x02\xfeoLK\x00\n\x1a"
30) "2.9783388088045439e-294"
31) "\x02\xfbM\x9cV\x00\t\xdf"
32) "2.671881978642153e-294"
33) "\x02\xfbI\xb7\x01\x80\t\xd5"
34) "2.6703927436380646e-294"
35) "\x02\xe9;\x1b\x01\x00\tI"
36) "1.2345442624106588e-294"
37) "\x02\xe8\xcc\xabG\x80\tD"
38) "1.2134362848024405e-294"
39) "\x02\xe8\xab4v\x00\t<"
40) "1.207040204881535e-294"
41) "\x02\xe8VLL\x80\t9"
42) "1.1908117494394802e-294"
43) "\x02\xe8A\xb34\x00\t7"
44) "1.1868747987381901e-294"
45) "\x02\xe8A\x8b\xca\x00\t5"
46) "1.1868453717697188e-294"
47) "\x02\xe8A$p\x80\t3"
48) "1.1867682098253855e-294"
49) "\x02\xe8@\xd8\xa2\x80\t1"
50) "1.1867116132198205e-294"
51) "\x02\xe8@\x85y\x00\t."
52) "1.1866495234829259e-294"
53) "\x02\xe8@% \x00\t'"
54) "1.1865775892730797e-294"
55) "\x02\xe8?\x90\x8c\x00\t$"
56) "1.1864666592262249e-294"
57) "\x02\xe8?YW\x80\t\""
58) "1.186425442513448e-294"
59) "\x02\xe8>\xfa\xbc\x80\t "
60) "1.186354809039771e-294"
61) "\x02\xe8>\xb0\x8d\x80\t\x1d"
62) "1.1862994227604611e-294"
63) "\x02\xe8=\xb4\xbb\x80\t\x1a"
64) "1.1861114109716155e-294"
65) "\x02\xe8<\xbe\x1a\x00\t\x18"
66) "1.1859272736850112e-294"
67) "\x02\xe8<R\xcb\x80\t\x16"
68) "1.1858471573780356e-294"
69) "\x02\xe86\x01\xf3\x80\t\x10"
70) "1.1846400042190911e-294"
71) "\x02\xe85\xb6\x16\x00\t\r"
72) "1.1845833624085694e-294"
73) "\x02\xe85\x1d\xe6\x80\t\x0b"
74) "1.1844697390212407e-294"
75) "\x02\xe8\x0f\xeda\x00\t\t"
76) "1.177361613956804e-294"
77) "\x02\xe6iKU\x80\b\xf9"
78) "1.0965827612653701e-294"
79) "\x02\xe6hr\xd4\x80\b\xf7"
80) "1.0964211170901962e-294"
81) "\x02\xe6g\x04Q\x00\b\xf5"
82) "1.0961474739896799e-294"
83) "\x02\xe6e\xbc\xc7\x00\b\xf3"
84) "1.0959029297571436e-294"
85) "\x02\xe6e,\x18\x80\b\xf1"
86) "1.0957949088679748e-294"
87) "\x02\xe6e\x00q\x00\b\xeb"
88) "1.0957623160943219e-294"
89) "\x02\xe6*\xc8\x06\x80\b\xcb"
90) "1.0846345167163807e-294"
91) "\x02\xe6)\xd7\n\x80\b\xbf"
92) "1.0844545951565264e-294"
93) "\x02\xe6&R\xf3\x00\b\xb5"
94) "1.0837825768146554e-294"
95) "\x02\xe5\x8b_\xd3\x80\b\xa8"
96) "1.0541666705823819e-294"
97) "\x02\xe5\x8aJq\x80\b\xa4"
98) "1.0539595735525378e-294"
99) "\x02\xdb\xa5\x94x\x00\b\xa0"
100) "6.7637738291561725e-295"
101) "\x02\xd9h\xf0\x83\x80\b\x9e"
102) "6.2165231431795857e-295"
103) "\x02\xd9N\xbe\xc0\x80\b\x96"
104) "6.1914901693937348e-295"
105) "\x02\xd9K\xffe\x80\b\x94"
106) "6.1888645051142944e-295"
107) "\x02\xce\xa4`\xf7\x80\x0b\xe0"
108) "3.748287140820869e-295"
109) "\x02\xce\x93W$\x00\x0b\xd8"
110) "3.7401456734679733e-295"
111) "\x02\xce\x93\x1f\xe7\x00\x0b\xd6"
112) "3.7400425697114939e-295"
113) "\x02\xc7 \xb9\xfb\x80\x0b\xca"
114) "2.8291064994853422e-295"
115) "\x02\xc7\x04\xd6\xdf\x80\x0b\xbd"
116) "2.8157811573889311e-295"
117) "\x02\xc7\x04\xd6<\x00\x0b\xbb"
118) "2.81577996529048e-295"
119) "\x02\xc6\xa9\xf8\x8e\x80\x0bp"
120) "2.7723614102207703e-295"
121) "\x02\xc6\xa9\x89\xaf\x80\x0bn"
122) "2.7721544663044883e-295"
123) "\x02\xc6\xa7\x97\x8f\x80\x0bl"
124) "2.7712247024245536e-295"
125) "\x02\xc3FBr\x80\x0bh"
126) "2.3577420448041622e-295"
127) "\x02\xc2\x1f\xd5R\x00\x0bf"
128) "2.2170560504078095e-295"
129) "\x02\xc2\x1e\x0e\xec\x00\x0bd"
130) "2.2162079033477617e-295"
131) "\x02\xc2\x1d\xcd\x9e\x80\x0bb"
132) "2.2160860140153989e-295"
133) "\x02\xc2\x1dE\x06\x80\x0b_"
134) "2.2158310580606177e-295"
135) "\x02\xc2\x1d\x06\x16\x80\x0b]"
136) "2.2157135835026378e-295"
137) "\x02\xc2\x1c\xd8%\x00\x0b["
138) "2.2156278289710039e-295"
139) "\x02\xc2\x1c\xafR\x00\x0bY"
140) "2.2155516294547766e-295"
141) "\x02\xc2\x1b\xbb\x0c\x00\x0bW"
142) "2.2150956864304048e-295"
143) "\x02\xc2\x1b8\xd9\x00\x0bS"
144) "2.2148526660423693e-295"
145) "\x02\xc2\x1a.\x9a\x80\x0bO"
146) "2.2143557141021976e-295"
147) "\x02\xc2\x1a\x1a\xec\x00\x0bM"
148) "2.2143189777839012e-295"
149) "\x02\xc2\x19\xffI\x80\x0bK"
150) "2.214267396741173e-295"
151) "\x02\xc1\xdd\x91\x99\x80\x0bI"
152) "2.1853928036744441e-295"
153) "\x02\xc1\xdd0.\x80\x0bG"
154) "2.1852109703823975e-295"
155) "\x02\xc1\xd5\x890\x80\x0bE"
156) "2.181554458107345e-295"
157) "\x02\xc1\xd5\x14\r\x80\x0bC"
158) "2.1813358192313437e-295"
159) "\x02\xc1\xd4\xca\xbc\x80\x0bA"
160) "2.1811989721621578e-295"
161) "\x02\xc1\xb6\x80\xd5\x00\x0b?"
162) "2.1667260985988985e-295"
163) "\x02\xc1\xaf?4\x80\x0b="
164) "2.1632587872946925e-295"
165) "\x02\xc1\xaf'\x12\x80\x0b;"
166) "2.1632137427428548e-295"
167) "\x02\xc1\xae\xe5\x8a\x00\x0b9"
168) "2.1630914232342929e-295"
169) "\x02\xc1\xaa\xcc\x10\x00\x0b7"
170) "2.1611325466457859e-295"
171) "\x02\xc1\x8a\x99\x10\x00\x0b+"
172) "2.1457467626311366e-295"
173) "\x02\xc1\x8aKW\x00\x0b)"
174) "2.1456016911763126e-295"
175) "\x02\xc1\x89\xe4\x98\x00\x0b'"
176) "2.1454099127938313e-295"
177) "\x02\xb4\x94~\x9d\x80\x0b\x03"
178) "1.258724947414792e-295"
179) "\x02\xaa\xee~\x9f\x80\n\xc6"
180) "8.2360076774478832e-296"
181) "\x02\xa2\x86a@\x00\n/"
182) "5.6651399804834274e-296"
183) "\x02\x9b\x9e\xbc\x88\x80\n\x0c"
184) "4.2232710989531531e-296"
185) "\x02\x9a\xf2\x8f\x18\x80\t\xf0"
186) "4.1204314269141392e-296"
187) "\x02\x9a\xdb\x91\xe3\x80\t\xdd"
188) "4.1067003028900665e-296"
189) "\x02\x89Tda\x80\t\x9a"
190) "1.9365271190156874e-296"
191) "\x02|\x14\x06>\x00\t\x17"
192) "1.0733314633725565e-296"
193) "\x02{\xcf\xa2]\x00\t\x0e"
194) "1.0631192968598284e-296"
195) "\x02j\xba\x95#\x80\b\xb7"
196) "5.1087466975425239e-297"
197) "\x02j+l\x01\x00\b\xad"
198) "5.0018613721475818e-297"
199) "\x02j*\xe4\x15\x80\b\xa7"
200) "5.001464968653466e-297"
201) "\x02j*\xe3\xcc\x00\b\xa5"
202) "5.0014641313136702e-297"
203) "\x02j*\xe1\x8d\x00\b\xa3"
204) "5.0014575806962294e-297"
205) "\x02j*\xe1\x8d\x00\b\xa2"
206) "5.0014575806962287e-297"
207) "\x02j*\xdb\xaf\x00\b\x9f"
208) "5.001440469344237e-297"
209) "\x02j*s\xab\x00\b\x9d"
210) "5.0011371130987095e-297"
211) "\x02j*q\xb1\x00\b\x9b"
212) "5.0011313485553614e-297"
213) "\x02j*q\x95\x00\b\x99"
214) "5.0011310295687717e-297"
215) "\x02j*qm\x80\b\x97"
216) "5.0011305795698332e-297"
217) "\x02j*qb\x00\b\x96"
218) "5.0011304485574838e-297"
219) "\x02j)2\xd8\x80\b\x93"
220) "5.0002014513845978e-297"
221) "\x02j)0u\x00\b\x91"
222) "5.0001944849453543e-297"
223) "\x02j)0'\x00\b\x8f"
224) "5.0001935963398568e-297"
225) "\x02j)-\xa8\x00\b\x8d"
226) "5.000186316610214e-297"
227) "\x02j)-\x7f\x80\b\x8b"
228) "5.0001858552188974e-297"
229) "\x02j) \xb4\x80\b\x89"
230) "5.0001485451804366e-297"
231) "\x02gaVF\x80\b6"
232) "4.468717823154972e-297"
233) "\x02d\xcf[\xaf\x80\b\x0c"
234) "3.9774636328185945e-297"
235) "\x02b\xfdfg\x00\x0b\xfc"
236) "3.6295742108307488e-297"
237) "\x02b\xfcI?\x00\x0b\xf8"
238) "3.6287425672253904e-297"
239) "\x02b\xd5\xc3\xe8\x80\x0b\xef"
240) "3.5999824800907356e-297"
241) "\x02b\xb2\xe3\x80\x80\x0b\xc6"
242) "3.5739432403271398e-297"
243) "\x02P\xe5.E\x80\x0b\x8e"
244) "1.6146135342192938e-297"
245) "\x02P\xe5)\x0e\x00\x0b\x8b"
246) "1.6146059269587794e-297"
247) "\x02P\xe5\">\x80\x0b\x88"
248) "1.6145959956531213e-297"
249) "\x02P\xe5 \x11\x80\x0b\x86"
250) "1.6145928228758043e-297"
251) "\x02P\xe5\x1eE\x00\x0b\x82"
252) "1.6145901997807326e-297"
253) "\x02P\xbfC\x88\x80\x0b\x80"
254) "1.6004589315751905e-297"
255) "\x02P\xbe^{\x00\x0b~"
256) "1.6001249212881415e-297"
257) "\x02P\xad2\xa7\x80\x0b|"
258) "1.5937148202889608e-297"
259) "\x02P\xad\x12\x81\x00\x0bz"
260) "1.5936679378047555e-297"
261) "\x02P\xa0\x01:\x00\x0bn"
262) "1.5887897727442437e-297"
263) "\x02P\x9e\x82o\x80\x0bl"
264) "1.5882315775436606e-297"
265) "\x02P\x9dw\xfe\x00\x0bj"
266) "1.5878430433347592e-297"
267) "\x02P\x9c8i\x00\x0bf"
268) "1.5873770210177376e-297"
269) "\x02P\x93\x7f\xc7\x00\x0b`"
270) "1.584121341365575e-297"
271) "\x02Py\xa5\xa3\x80\x0bR"
272) "1.5744706100457731e-297"
273) "\x02H\xf6\xba\x9e\x80\x0bO"
274) "1.1928469707401533e-297"
275) "\x02H\xf0zX\x00\x0bM"
276) "1.191680190426359e-297"
277) "\x02H\xee\xd1\xfb\x80\x0bK"
278) "1.1913707834039846e-297"
279) "\x02H\xed\xba\xa3\x80\x0bI"
280) "1.1911671104673192e-297"
281) "\x02H\xe3n\xed\x00\x0bD"
282) "1.1892453800379119e-297"
283) "\x02H\xe3(?\x80\x0bB"
284) "1.1891938480393722e-297"
285) "\x02H\xda\xe6\x1c\x00\x0b@"
286) "1.1876524037370815e-297"
287) "\x02H\\\x9b\x12\x80\x0b3"
288) "1.1640794500787534e-297"
289) "\x02G\x1b\x92\x99\x80\x0b-"
290) "1.1041577482537909e-297"
291) "\x02G\x14\xc5\xac\x80\x0b+"
292) "1.102888418023982e-297"
293) "\x02G\x14\xc0\xda\x80\x0b)"
294) "1.1028849034753207e-297"
295) "\x02G\x14\x83I\x80\x0b'"
296) "1.1028400146572929e-297"
297) "\x02G\x14\x82\xf3\x00\x0b%"
298) "1.1028397682971149e-297"
299) "\x02G\x14w\xa1\x80\x0b#"
300) "1.1028315159431882e-297"
301) "\x02G\x14wF\x80\x0b!"
302) "1.1028312567665848e-297"
303) "\x02G\x14p6\x80\x0b\x1f"
304) "1.1028261074116581e-297"
305) "\x02G\x14o\x99\x00\x0b\x1d"
306) "1.1028256588367679e-297"
307) "\x02G\x14o\x92\x00\x0b\x1c"
308) "1.102825638900106e-297"
309) "\x02G\x14k\xee\x00\x0b\x19"
310) "1.1028229844759952e-297"
311) "\x02G\x14i\x16\x00\x0b\x17"
312) "1.1028209110631706e-297"
313) "\x02G\x14g\xba\x80\x0b\x15"
314) "1.102819921350318e-297"
315) "\x02G\x14g\x9c\x80\x0b\x13"
316) "1.1028198359074815e-297"
317) "\x02G\x14d\xc2\x00\x0b\x11"
318) "1.1028177553744205e-297"
319) "\x02G\x14d\x10\x80\x0b\x0f"
320) "1.1028172498376395e-297"
321) "\x02G\x14d\x06\x80\x0b\x0e"
322) "1.1028172213566939e-297"
323) "\x02G\x14cc\x00\x0b\x0b"
324) "1.1028167556932363e-297"
325) "\x02G\x14c`\x00\x0b\n"
326) "1.1028167471489525e-297"
327) "\x02G\x14cZ\x80\x0b\t"
328) "1.1028167314844324e-297"
329) "\x02G\x144\xb5\x80\x0b\x05"
330) "1.1027827223875428e-297"
331) "\x02G\x14.\xee\x80\x0b\x03"
332) "1.1027785100557195e-297"
333) "\x02G\x14($\x00\x0b\x01"
334) "1.1027735586433633e-297"
335) "\x02E\xd3\xd5\xb9\x00\n\xf5"
336) "1.0429845951124792e-297"
337) "\x02E\xd3\xd2\b\x00\n\xf3"
338) "1.0429819036631396e-297"
339) "\x02E\xd3\xcd\x17\x00\n\xf1"
340) "1.0429783008235476e-297"
341) "\x023\xdd\x8f\x9d\x80\bO"
342) "4.7461690581895211e-298"
343) "\x02/z\xea\r\x80\b\n"
344) "3.760545745711677e-298"
345) "\x02/B@\x80\x80\x0bh"
346) "3.7341053105353015e-298"
347) "\x02.\x94\xb5\x14\x80\x0bC"
348) "3.6531238720590523e-298"
349) "\x02.\x94\x94\x8e\x00\x0bA"
350) "3.6530645854111063e-298"
351) "\x02,w\bZ\x00\x0b\""
352) "3.4003612170829979e-298"
353) "\x02\x1a'\x14\x81\x80\tM"
354) "1.5620686703106202e-298"
355) "\x02\n\xf8\x1a\x1b\x00\b2"
356) "8.0541839890337761e-299"
357) "\x02\x00]\x9a\xdc\x00\x0b;"
358) "4.8875073090149035e-299"
359) "\x02\x000&I\x80\x0b9"
360) "4.8344800163411153e-299"
361) "\x01\xf8\xfa\x10\a\x80\n\xa3"
362) "3.7295912578072465e-299"
363) "\x01\xeeI\x8d\x18\x00\t\xfd"
364) "2.2612835000410468e-299"
365) "\x01\xecy:\x11\x80\x0bf"
366) "2.1258656896935245e-299"
367) "\x01\xecx\xae>\x00\x0bd"
368) "2.1257063944309196e-299"
369) "\x01\xe7?Th\x80\nd"
370) "1.7356748465528535e-299"
371) "\x01\xe7>\xb73\x80\nb"
372) "1.7354957503579818e-299"
373) "\x01\xdd\r!/\x00\t\x14"
374) "1.0845003911915548e-299"
375) "\x01\xdc\xa5\xa8\x8b\x80\b\xba"
376) "1.0694119617627475e-299"
377) "\x01\xdc\xa5\x85\xfa\x00\b\xb8"
378) "1.0693922709716364e-299"
379) "\x01\xc2\xc2\x0c\r\x00\t8"
380) "3.5012311155568145e-300"
When I try scan this zset I get wrong score result:
127.0.0.1:6379[1]> "ZSCAN" "feed:\x01\xda\x8dq\x02\x80\b\xa4:followings" "0" "match" "*:\x006D\x92:*"
1) "40"
2) 1) "\x03\x16\xf0\x9fv\x00\t\xe1:\x00\x01}W:\x006D\x92:"
2) "0"
score is 0, but must be "8.9795875511162971e-294"
Metadata
Metadata
Assignees
Labels
No labels
Activity
michael-grunder commentedon Dec 1, 2014
Hey,
I just quickly tested this but it works just fine for me. What version of Redis are you running?
grdy commentedon Dec 1, 2014
2.8.8
michael-grunder commentedon Dec 1, 2014
Well perhaps you could try it against a different instance? Assuming the data isn't proprietary and you wanted to upload it somewhere, I would be happy to take a look. But like I said that worked just fine for me.
Cheers!
Mike
mattsta commentedon Dec 1, 2014
A general INFO output would help too. Floating point isn't always stable across architectures.
It works for me using ridiculously tiny values like in your example:
grdy commentedon Dec 2, 2014
Yes I have the same result, but it seems like my situation reproduces only on not "0" cursor.
grdy commentedon Dec 2, 2014
Have tried on different instances, same result, my dump is:
https://www.dropbox.com/s/ror2ancvuhe468z/dump.rdb?dl=0
For reproduce:
for the key "\x03\x16\xf0\x9fv\x00\t\xe1:\x00\x01}W:\x006D\x92:" score is 0, but
score is "8.9795875511162971e-294"
michael-grunder commentedon Dec 2, 2014
OK so this is a weird one that I'm curious about but I shouldn't even be awake right now. 😪
I think I've found something relevant that would seem to be more than coincidence, but I'll have a look in the A.M.
I'm using this default config for my toy instance:
zset-max-ziplist-entries 128Now, if I add up to 128 entries (meaning ziplist), the results are correct. So the following zset has 128 elements:
But, if I add 129 elements (meaning it will be a skiplist), they all come back zero for me:
However the scores are correct:
So it must be a difference in how ZSCAN is interacting with a ziplist or a skiplist. I know the ziplist is going to always come back all at once as it's a blob but that doesn't totally explain it. I'll take a look in the morning but I bet 38 people will have sorted it. Good luck!
Cheers guys
Mike
mattsta commentedon Dec 2, 2014
Oh, that helps! The SCAN code does have different code paths for ziplists versus non-ziplists:
ziplist (db.c:525):
non-ziplist (db.c:382):
If we change the non-ziplist version to actually write a double, it works:
key = dictGetKey(de); incrRefCount(key); - val = createStringObjectFromLongDouble(*(double*)dictGetVal(de)); + char dbuf[64]; + size_t sz = snprintf(dbuf, sizeof(dbuf), "%.17g", *(double *)dictGetVal(de)); + val = createStringObject(dbuf, sz);The LongDouble function is expecting a 128-bit float (long double) and prints incorrectly when given regular 64-bit doubles.
michael-grunder commentedon Dec 2, 2014
@mattsta I'm literally on that line right now and was about to ping this exact message. I knew you would get it first! Nice find! 👍
Fix ZSCAN return value for very double values
antirez commentedon Dec 2, 2014
Thanks, I'm going to release 2.8.18, likely tomorrow, this is a good fix to have inside.
antirez commentedon Dec 2, 2014
Hey, just checked the issue and actually it has nothing to do with long doubles vs doubles. In the original code, the double is casted to long double that has more precision, so you can't get zero for this. The only difference is that we print stuff with "f" and not "g" and do hand trimming, since this was a requirement for floats increment commands like INCRBYFLOAT, otherwise results are unexpected... and not good for normal applications where you, for example, increment a balance and want 0.10 -> 0.20 and not stuff like 0.20000001111111 or exp notation. And still with 17 digits of precision you have plenty of room.
However, why it creates this "pseudo" bug? Because "f" does not use exponential notation, and the values in the range of our original poster, are only representable in exponential notation since they are so small.
Use exp format and more precision output for ZSCAN.
antirez commentedon Dec 2, 2014
What about 92c5ab4?
mattsta commentedon Dec 2, 2014
If it works, great!
If we are supposed to catch cases like "0.10 -> 0.20" then we need tests for those things too. It's always better to have tests tell us things are broken so you don't have to type out reasons all the time. :)
There's also the inf inconsistency we aren't managing here (inf, +inf, -inf, etc, depending on platform).
michael-grunder commentedon Dec 2, 2014
So if I understand the change correctly,
hincrbyandhincrbyfloatwill return the "prettier" values like .20 vs 0.20000001111111, but zscan would return the latter. I suppose this is now more a philosophy discussion, a.k.a. do you want stuff like 0.20000001111111 coming back from zscan when the user probably wants to see .20?antirez commentedon Dec 2, 2014
@mattsta yes, we should have tests indeed... About +inf/-inf, you are right, it should be fixed like is fixed in other places. This should be tested as well even if it will fail only on Solaris.
@michael-grunder ZSCAN and INCRBYFLOAT are a bit different, since ZSCAN is presenting a result, and is used for example for import scripts, so to lose information is not a good idea IMHO. Instead the INCRBYFLOAT will use this semantic in order to modify an existing value into a new one, so it is a transformation with a "clean to see" semantic and when GET is called against the key the user will see exactly what originated from INCRBYFLOAT.
What is missing in this story is a pretty printing option for ZSCORE just in case the user is using a sorted set score as something that may be user-facing. This can be solved client side, or in theory with a ZSCORE option as well... but nobody asked for this so far :-)
mattsta commentedon Dec 2, 2014
Maybe I'm just having a dumb day, but I don't see how the code stops that.
If I give it "0.10 + 0.10" then createStringObjectFromLongDouble returns 0.20000000000000001.
The loop in the function just says "remove all trailing zeros" but a 1 is not a trailing zero, so nothing gets removed.
If we pass in 0.2000000000, then the function would return just 0.2.
If we wanted the function remove the bad floating point math, we'd have to check if the last digit was the only non-zero digit after non-zero digits at the beginning. (So, it would remove the '1' in things like 0.2000000001 or 0.55000000001, but not in the case of 0.3332111)
The correct way to do all that is a little more complicated. See "Printing Floating-Point Numbers Quickly and Accurately" at http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf and an implementation of it at http://mochiweb.googlecode.com/svn/trunk/src/mochinum.erl
antirez commentedon Dec 2, 2014
@mattsta basically with a precision set to 17 and no more, the internal precision of the long double is good enough to approximate normal numbers in a sensible way, so you end usually with just zeroes at the end, and we trim that. If you play enough with adding/removing numbers however, you eventually end with some trailing non-zero digit and it shows up. So it's kinda of poor's man printing floating numbers not quickly and accurately, but reasonably well. For example with precision set to 21 (like it should be in theory) and the "g" modifier, this is the behavior:
Eventually after a few experiments to avoid exponential notation, and at the same time, avoiding the zero-paddings, and the non-significant digits artifacts, to use a long double with 17 digits of precision, removing the tailing zeroes, was the best I was able to achieve at the time without resorting to more complex techniques.
antirez commentedon Dec 2, 2014
p.s. Perhaps another more sensible, but time consuming alternative, is to set to zero the non significant digits and convert back the result into a double and see if it is equal to the previous one. For example in 1.10000000000000000002 you can set to 2 to 0, and internally the double will be the same. Probably too much CPU in our case.
Regression test for issue #2175.
Use exp format and more precision output for ZSCAN.
Regression test for issue #2175.
Use exp format and more precision output for ZSCAN.
Regression test for issue #2175.
antirez commentedon Dec 3, 2014
Regression test added, I merged the fix I proposed in all the branches. Thank you!
Regression test for issue redis#2175.
ZSCAN: format skiplist scores with d2string(), consistent with ZSCORE (…