Fix float accuracy issues#12
Conversation
Codecov Report
@@ Coverage Diff @@
## master #12 +/- ##
============================================
+ Coverage 24.46% 24.63% +0.16%
- Complexity 460 465 +5
============================================
Files 89 89
Lines 6302 6304 +2
Branches 1048 1048
============================================
+ Hits 1542 1553 +11
+ Misses 4545 4536 -9
Partials 215 215
Continue to review full report at Codecov.
|
| break; | ||
|
|
||
| case FLOAT: | ||
| out.writeDouble(Double.parseDouble(((Number) obj).floatValue() + "")); |
There was a problem hiding this comment.
What is the purpose of + ""?
There was a problem hiding this comment.
My mistake, I have modified it, please review it.
| break; | ||
|
|
||
| case FLOAT: | ||
| out.writeDouble(Double.parseDouble(String.valueOf(((Number) obj).floatValue()))); |
There was a problem hiding this comment.
Is out.writeFloat(((Number) obj).floatValue()) not ok?
There was a problem hiding this comment.
There is no such method writeFloat()
There was a problem hiding this comment.
Then how about out.writeDouble(((Number) obj).floatValue()) ? I am concerning the float->String->double conversion, the intermediate String conversion should be avoid.
There was a problem hiding this comment.
When single precision is double precision, double precision will complement the single precision. Lead to deviation.
For example:
99.8F -> 99.80000305175781
There was a problem hiding this comment.
Okay, I got what you mean. It actually is:
jshell> float f = 99.8f
f ==> 99.8
jshell> double d = f;
d ==> 99.80000305175781
I do not have permission to merge this. I will approve this change.
This repo should be transfer to ASF soon. You should also have permission.
dubbo泛化调用,float类型数据结果不正确
apache/dubbo#3861