triground | R Documentation |
Round the input for or output from trigonometric functions, to overcome some issues relating to rounding error.
cround(x) sround(x)
x |
The number or numbers to be rounded. Can be a vector, matrix, numeric, list or data frame. |
The function cround
rounds a number such that it is between -1
and 1. This overcomes rounding error whereby a number that has
absolute value of 1 or very slightly less, is calculated by R to have
absolute value of very slightly larger than 1, which can trigger
errors if that calculated value is automatically passed to
e.g. acos
or asin
. The function
sround
rounds a number that is extremely close to 0, to 0; this
overcomes a minor calculation error in some R functions
(e.g. trigonometric functions) and thus may trigger errors in some R
functions (e.g. acos
or asin
, if the value
being rounded is to be added to or subtracted from 1 or -1.
The rounded values, in the same format as the input.
cround
will round any number greater than 1 to
1; and any number less than -1 to -1. Care should be taken when using
cround
to ensure that its input are between (or close to one of) -1
and 1, that is that genuinely erroneous values are identified as such.
Tom Lawrence <email: tjlawrence@bigpond.com>
x <- c(-1-(10^17), -1+(10^-17), -0.5, 0, 0.5, 1-(10^-17), 1+(10^-17)) cround(x) y <- c(-0.5, -10^-17, 10^-17, 0.5) sround(y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.