필터 지우기
필터 지우기

change integer division rounding default

조회 수: 2 (최근 30일)
Andrea Carignano
Andrea Carignano 2020년 6월 18일
답변: Ayush Laddha 2020년 6월 18일
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일
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 -

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by