change integer division rounding default

In matlab and simulink int32(7)/int32(4) = 2.
I would like to have int32(7)/int32(4) = 1 like any other language (for example C).
Is there a way to change this default?
I know the function idivide, but this function is slower and I'd prefere to see the symbol "/" that is clearer.

답변 (1개)

Ayush Laddha
Ayush Laddha 2020년 6월 18일

0 개 추천

My understanding of your question is that you want to change the default answer received when we use division operator. You cannot alter the default operation but there are some other methods which you can use -
1.Use fixed-point numeric objects and settings.
F = fimath('RoundingMethod', 'floor');
A = fi([7], 1, 32, 0, F);
B = fi([4], 1, 32, 0);
ans = A/B;
Documentation links -
2. Use other datatypes like single/double.
floor(single(7)/single(4))
Or
floor(7/4) % By default, MATLAB stores all numeric variables as double-precision floating-point values
3. Use idivide function.
idivide(int32(7), int32(4))
Link to refer to the documentation of idivide function -

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2020년 6월 18일

답변:

2020년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by