[GODRIVER-1921] Decimal128 isZero Created: 16/Mar/21 Updated: 07/Apr/21 Resolved: 24/Mar/21 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | BSON |
| Affects Version/s: | 1.5.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Swee Tat Lim | Assignee: | Benji Rewis (Inactive) |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Documentation Changes: | Not Needed |
| Description |
|
``` import github.com/rs/zerolog/log p := primitive.NewDecimal128(0, 0) log.Debug(). ``` Running this code gives me the following: |
| Comments |
| Comment by Swee Tat Lim [ 07/Apr/21 ] |
|
Hi, My current idea of a fix will be to get a fork of mongo driver, and apply the patch you set up in pull 620 |
| Comment by Benji Rewis (Inactive) [ 24/Mar/21 ] |
|
Hello again sweetat@withevo.com! After further investigation, it seems that all MongoDB drivers represent all zeros in bits (primitive.NewDecimal128(0,0)) as “0E-6176” when stringified. At the moment, it is unclear if this is a flaw in our interpretation of decimal128 arithmetic (our spec is based on conversions described here) or a way of simplifying mathematic operations with a decimal128 of all zeroes. We will investigate further within the larger drivers department, but for now I am closing this smaller pull request. Let us know if you need help finding a workaround for this behavior in the meantime! |
| Comment by Benji Rewis (Inactive) [ 23/Mar/21 ] |
|
sweetat@withevo.com Thanks again for your report! This does appear to be a bug; -6176 is the default exponent that never gets set when the decimal128 is zero. This means that the stringified version is OE-6176 when it should just be 0. A fix is in review.
|
| Comment by Esha Bhargava [ 22/Mar/21 ] |
|
sweetat@withevo.com Thank you for reporting this issue. We'll look into this and get back to you soon. |
| Comment by Swee Tat Lim [ 16/Mar/21 ] |
|
``` {"level":"debug","testData.TestPrimitiveDecimal128":"16.72","p":"0E-6176","mongo.DecimalZero":"0","p.IsZero":true,"mongo.DecimalZero.IsZero":false,"time":"2021-03-16T19:44:54+08:00","message":"init"}```
p gives an odd "0E-6176" when converted to string. Why is that the case?
My expectation with the use of IsZero function is that it should provide the number where decimal representation is zero. |