i had an array of 1*10 double named Q(i). I want to find modulo function of these 10 values with 256. But am getting wrong answers. May be its the problem of types. Will you please help me to solve?

5 件のコメント

Walter Roberson
Walter Roberson 2017 年 7 月 21 日
Could you give some examples of the values and what you are observing ?
SNEHA P S
SNEHA P S 2017 年 7 月 21 日
編集済み: Walter Roberson 2017 年 7 月 21 日
Q(7) = 4.078e+09
And i would like to mod it using equation
s(i) = mod(Q(i),256)
and i am getting
s(7) = 25.8600
But when i am trying to do the same in the command window using the exact numerical value ie., 4.078e+09, am getting it right. And its get wrong when am using Q(7) instead of value,
Adam
Adam 2017 年 7 月 21 日
And what is the problem? That seems like the right answer to me.
SNEHA P S
SNEHA P S 2017 年 7 月 21 日
sorry, Q(7) value is like 4.078e+09. And when use mod function with 256 the exact value is 128. And am geeting 25.8600.
Walter Roberson
Walter Roberson 2017 年 7 月 21 日
Give the command
format long g
And then display the Q value again

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2017 年 7 月 21 日

0 投票

2^53 = 9007199254740992 is the largest integer expressed in double precision that you can reliably take mod() 10 of. After that, the difference between adjacent representable double precision numbers becomes more than 1.
You can extend the range by using uint64(), allowing you to get to 18446744073709551615 . Beyond that you would need to use the Symbolic Toolbox, or use one of the extended precision File Exchange contributions.

2 件のコメント

SNEHA P S
SNEHA P S 2017 年 7 月 21 日
when iam trying to do the same in the command window using the exact numerical value ie., 4.078e+09, am getting it right. And its get wrong when am using Q(7) instead of value.
Jan
Jan 2017 年 7 月 21 日
@SNEHA P S: Then compare the two values:
Q(7) - 4.078e+09
Note that the short format for the command window does not let you distinguish 4078000000 and 4078000001 or 4077999999.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2017 年 7 月 21 日

コメント済み:

Jan
2017 年 7 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by