change integer division rounding default
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Ayush Laddha
am 18 Jun. 2020
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 -
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!