[CDRIVER-1945] bson_as_json outputs doubles as integers Created: 08/Dec/16 Updated: 29/Jan/24 Resolved: 05/Jan/17 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | libbson |
| Affects Version/s: | 1.5.0 |
| Fix Version/s: | 1.6.0 |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | David Golden | Assignee: | A. Jesse Jiryu Davis |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Epic Link: | libbson corpus | ||||||||||||||||||||
| Description |
|
Example code:
Actual output:
Possibly expected output:
Some JSON encoders will preserve a fractional part of zero. This behavior surprised as least one user as shown on this stack overflow post. |
| Comments |
| Comment by Githook User [ 10/Feb/17 ] |
|
Author: {u'username': u'jmikola', u'name': u'Jeremy Mikola', u'email': u'jmikola@gmail.com'}Message: Use exactly representable floating point numbers in tests
|
| Comment by Githook User [ 10/Feb/17 ] |
|
Author: {u'username': u'jmikola', u'name': u'Jeremy Mikola', u'email': u'jmikola@gmail.com'}Message: Use exactly representable floating point numbers in tests
|
| Comment by Githook User [ 02/Feb/17 ] |
|
Author: {u'username': u'jmikola', u'name': u'Jeremy Mikola', u'email': u'jmikola@gmail.com'}Message: Use exactly representable floating point numbers in tests
|
| Comment by Githook User [ 06/Jan/17 ] |
|
Author: {u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}Message: |
| Comment by Jeremy Mikola [ 27/Dec/16 ] |
|
For PHP, this has implications for the Double: -0.0 test case. If bson_as_json() emits "-0" for double value -0.0, we cannot reliably compare it with the expected canonical JSON string: {"d" : -0.0}. Were libbson to emit "-0.0", PHP's json_decode() function would be able to properly convert it to a negative zero floating point value in PHP, and it would be preserved when we call json_encode() as well. |
| Comment by David Golden [ 08/Dec/16 ] |
|
I don't have strong feelings about this as Javascript doesn't distinguish numeric types. But we should make a call one way or another for the record. |