[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #55682] round(X,N) and round(X,N,type)
From: |
Rik |
Subject: |
[Octave-bug-tracker] [bug #55682] round(X,N) and round(X,N,type) |
Date: |
Tue, 21 May 2019 13:14:09 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko |
Follow-up Comment #5, bug #55682 (project octave):
Documentation on Matlab's round function is available here
(https://www.mathworks.com/help/matlab/ref/round.html).
They seem to implement the scheme suggested by Michael in comment #2. For
example, if you use the two-input form "round (x,n)" they require that x be a
floating point class (single or double). Similarly, they have an example of
the possible confusion that can result when a floating point number looks like
it should round in one direction, but doesn't because of extra precision.
format short
x = 112.05 - 110
x = 2.05
y = round (x, 1)
%% Expected value from above would be 2.1
y = 2.0
%% Check significant figures
format long
x
x = 2.049999999999997
So this wouldn't be that hard to implement.
We could alse decide whether we want to be nicer than Matlab and work with
integer inputs when n != 0. This would require converting to doubles,
rounding, and then converting back to the original type. Because of
saturation, you could get some weird effects though.
round (uint8 (251), -2)
=> 255
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?55682>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #55682] round(X,N) and round(X,N,type),
Rik <=
- [Octave-bug-tracker] [bug #55682] round(X,N) and round(X,N,type), Rik, 2019/05/24
- [Octave-bug-tracker] [bug #55682] round(X,N) and round(X,N,type), Rik, 2019/05/24
- [Octave-bug-tracker] [bug #55682] round(X,N) and round(X,N,type), Rik, 2019/05/24
- [Octave-bug-tracker] [bug #55682] round(X,N) and round(X,N,type), John W. Eaton, 2019/05/25
- [Octave-bug-tracker] [bug #55682] round(X,N) and round(X,N,type), Rik, 2019/05/25