Function y = roundoff(x,n)
y = roundoff(..., ty)
y = roundoff(..., di)
returns the value by rounding x by n significant digits
(at default), or by rounding x by n decimals (if input
argument ty is 'dec').
Note that e.g. 1.234e5 has got 4 significant digits.
Input argument di indicates the direction of rounding:
'-inf' : rounding towards negative infinity (via an
internal call to function floor());
'+inf' : rounding towards positive infinity (via an
internal call to function ceil());
'zero' : rounding towards zero (via an internal call to
function fix());
At default, and for other values of di, rounding is
effectuated by an internal call to function round(). This
is rounding to the nearest integer, and ---if there are
two nearest integers--- taking the one further away from
zero.
The function is also useful for printing module numbers,
like angles. E.g. rounding angles by 1 decimal:
printf( "%5.1d", mod(roundoff(angle,1,'dec'),360) )
When the angle is very close to 360 degrees, this will
print "0.0". Contrarily, issuing simply:
printf( "%5.1d", mod(angle,360) )
will unfortunately print "360.0" for angles very close to
360 degrees.
(c) 2026 fabien van mook
2026.08.20 release of this file within package "fvm-miscellaneous" under GNU GPLv3+