by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 4.1, Creation date: 2017-08-12, Last change: 2025-09-14
y=rounds(x,s)
x: | floating point number | |
s: | number of |
y: | rounded x |
This function, named rounds, is a utility from the SG-Library designed to improve numerical accuracy in calculations involving trigonometric functions and vector operations. It is an auxiliary procedure introduced in SolidGeometry 4.1 by Tim C. Lueth.
x should be rounded.x to s significant digits.The function rounds is a simple wrapper around the round function with the 'significant' option. It takes two inputs, x and s, and returns y, which is x rounded to s significant digits.
The function is particularly useful in scenarios where numerical precision is critical, such as in trigonometric calculations or when computing cross or dot products. The function helps mitigate issues related to numerical inaccuracies that can arise in such computations.
Examples of usage include:
Double = rounds(1,12): Rounds the number 1 to 12 significant digits.Single = rounds(1,6): Rounds the number 1 to 6 significant digits.Half = rounds(1,3): Rounds the number 1 to 3 significant digits.The function is a straightforward implementation that leverages MATLAB's built-in round function, specifically using the 'significant' option to achieve the desired precision.