Discussion:
Round function
Rory Conolly
2018-11-16 13:40:50 UTC
Permalink
The round function in Octave rounds to the nearest integer while round in MATLAB supports rounding to arbitrary precision:

round(x,n) rounds x to n decimal places.

This is just a suggestion/request that it would be handy for the Octave function to work like the equivalent MATLAB function. This capability can be important when needing to compare numbers using == when numerical noise can cause problems.

Sent from my iPhone
Juan Pablo Carbajal
2018-11-16 14:21:27 UTC
Permalink
This is actually an easy fix,
new_round = @(x, n=0) round (x * 10^n) * 10^(-n)

If you could send a patch to the patch tracker with:
1. extended documentation
2. new code
3. a few test cases

I would be happy to apply the patch and push it.
Post by Rory Conolly
round(x,n) rounds x to n decimal places.
This is just a suggestion/request that it would be handy for the Octave function to work like the equivalent MATLAB function. This capability can be important when needing to compare numbers using == when numerical noise can cause problems.
Sent from my iPhone
Windhorn, Allen E [ACIM/LSA/MKT]
2018-11-16 14:48:31 UTC
Permalink
-----Original Message-----
Post by Juan Pablo Carbajal
This is actually an easy fix,
new_round(pi, 1.5)
ans = 3.1307

Maybe new_round = @(x, n=0) round (x * 10^round(n)) * 10^(-round(n))?
Depending on what you expect it to do.

Regards,
Allen

Loading...