arekdygas opened a new issue #1152: Inconsistent sum and sumsqr aggregates of floating point numbers URL: https://github.com/apache/couchdb/issues/1152 ## Expected Behavior Running a query with reduce against a view should always return the same aggregated value, if involved documents values didn't change. Assuming we have four documents containing property with following values: -0.2, -0.1, 0.1, 0.2, then running _sum_ against these values should always return 0.0 (or other floating point number close to 0.0, but always the same). ## Current Behavior Aggregated values for _sum_ and _sumsqr_ might give different results on multiple view queries. For sample document values -0.2, -0.1, 0.1, 0.2, returned sum is one of the following: -0.0000000000000000277555756156 0 0.0000000000000000277555756156 ## Possible Solution I don't know how it works internally, so no idea. ## Steps to Reproduce (for bugs) 1. Create new database _aaa_ 2. Create design document: ``` { "_id": "_design/dd", "views": { "v": { "reduce": "_sum", "map": "function (doc) {\n emit(doc._id, doc.num);\n}" } }, "language": "javascript" } ``` 3. Add two documents with `num` property. For first document set it to -0.1, for second to 0.1. 4. Execute http://127.0.0.1:6984/aaa/_design/dd/_view/v?reduce=true a few times. Result should be always 0 (which is ok) 5. Add next 2 documents, this time with `num` set to -0.2 and 0.2 6. Execute above query again, after some tries two non 0 value should be returned. 7. Add next 2 documents (-0.3, 0.3). Running a query might now return four non-zero values. 8. Modify design document, by replacing `emit(doc._id, doc.num)` with `emit(doc._id, doc.num + 1.0)`. 9. Execute query again. 6 will be returned all the times (which is ok). 10. Modify design document, by replacing `emit(doc._id, doc.num + 1.0)` with `emit(doc._id, doc.num + 0.0)`. 11. Execute query again. Results are the same as in point 7. 12. Delete all documents except single one (doesn't matter which) and modify design doc by replacing `emit(doc._id, doc.num + 0.0)` with ``` emit("-3", -0.3); emit("-2", -0.2); emit("-1", -0.1); emit("1", 0.1); emit("2", 0.2); emit("3", 0.3); ``` 13. Execute query again. The returned value will always be the same (for me it was -2.7755575615628914e-17). As a side note: I created documents with `num` property from within Fauxton, leaving their default _id. When I did this again, this time creating documents with custom _id ("1" for num 0.1, "-1" for -0.1, "2" for 0.2, etc.), the results were different. For example, in p. 7 above, I got eight non-zero results instead of four... ## Context I'm trying to get consistent data on each request, without having to round the values returned. Additionally, seeing these aggregates changing on subsequent request makes me worrying, if it doesn't mean there's something wrong with aggregate index persistence... ## Your Environment * Version used: tested on 1.5.1; 2.1.1 (custom build); 2.1.1 (official installer); also tested on Cloudant where this works as expected * Browser Name and version: Chrome 63.0.3239.132 * Operating System and version (desktop or mobile): Windows 7 Pro SP1; Windows Server 2012 R2 Standard * Link to your project: ---
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
