cround: Rounding for Trigonometric Functions

View source: R/cround.R

trigroundR Documentation

Rounding for Trigonometric Functions

Description

Round the input for or output from trigonometric functions, to overcome some issues relating to rounding error.

Usage

cround(x)
sround(x)

Arguments

x

The number or numbers to be rounded. Can be a vector, matrix, numeric, list or data frame.

Details

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.

Value

The rounded values, in the same format as the input.

Warning

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.

Author(s)

Tom Lawrence <email: tjlawrence@bigpond.com>

Examples

  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)

baddstats/spherstat documentation built on Feb. 6, 2023, 1:45 a.m.