[Convert from Double to Single]
100 次查看(过去 30 天)
显示 更早的评论
Hello Everyone,
Currently, during Simulation I have a issue, Please help me........
Issue : ( at the command windown)
value = 214748364.7 // Data type is default double.
value_single = single(value) // The result of this convertion is 214748368
my expectation value is value_single = 214748364.7
What is happened ?
Please help me.............!!!
Thank you in advance.
2 个评论
Shubham Gupta
2019-11-15
I think What you are expecting is not possible for a single type value. It has something to do with the precision for single. Either reduce the value or if you want to use big numbers then I would suggest using double type.
采纳的回答
Walter Roberson
2019-11-15
>> flintmax('single')
ans =
single
16777216
your 214748368 exceeds that, so you have exceeded the point at which single precision floating point numbers start being spaced 1.0 or more further apart.
>> log2(214748364.7)
27.6780719044408
So you would need 28 bits at least just to represent the integer portion. https://en.wikipedia.org/wiki/Single-precision_floating-point_format says that for IEEE 754 single precision, there are only 23 explicit bits available for the fraction; there is also one "hidden" bit, so you can only get 24 bits worth but you need more than 28 bits for the representation.
>> eps(single(214748364.7))
ans =
single
16
3 个评论
Steven Lord
2019-11-15
As a metaphor, unless he's talking to his accountants or the IRS Bill Gates probably doesn't describe his fortune down to the last cent. In casual conversation he rounds to a "nice" number. If you were to give him a $1 bill, it doesn't change how he reports his wealth. If you were to give him a million dollars, that might cause him to change his statement of his fortune (or that might require multiple millions.)
The "nice" number to which Gates rounds his wealth is the closest "representable" number to his actual wealth. How much money he would have to gain to change that nice number to the next larger or smaller representable number is eps, and if we operate on the assumption from the first paragraph it's somewhere between 1 and a million.
Since neither of us has as much money as Bill Gates does, our eps values are smaller ;)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!