Missing values ​​occur after converting data type.

Problem :
From the figure above, I calculated by using data type as double.
And when I convert the data type from double to uint16, the value before and after data type conversion block are not same even if there is no process.
Questions :
Can you explain the reason and solution for this problem?

댓글 수: 4

Mehmed Saad
Mehmed Saad 2020년 4월 8일
편집: Mehmed Saad 2020년 4월 8일
integer rounding mode Floor, i guess
you value might be 4-eps
change it to round (i dont know if that's an option but i think it should be)
If changing the integer rounding mode to "round", it can solve the problem.
But I would like to know why is the value missing when passing the data type conversion?
your value might be a bit smaller than 4 and it's not showing it because of the format
for example, type following in cmd
4 - 1e-15
ans =
4.0000
Now type
format long
4- 1e-15
ans =
3.999999999999999
floor(ans)
ans =
3
Example above
I tried to convert the data type from double to single before converting to uint16. It can solve the problem.
I think the root cause is the conversion of data types by converting from large data types (double) to small data types (uint16). there is a chance that the value will missing from the conversion.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

제품

릴리스

R2014a

태그

질문:

2020년 4월 8일

댓글:

2020년 4월 8일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by