File: isZero.Rd

package info (click to toggle)
r-cran-r.utils 2.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,864 kB
  • sloc: sh: 18; makefile: 6
file content (79 lines) | stat: -rw-r--r-- 2,266 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Do not modify this file since it was automatically generated from:
% 
%  isZero.R
% 
% by the Rdoc compiler part of the R.oo package.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\name{isZero}
\alias{isZero.default}
\alias{isZero}

\title{Checks if a value is (close to) zero or not}

\usage{
\method{isZero}{default}(x, neps=1, eps=.Machine$double.eps, ...)
}

\description{
  Checks if a value (or a vector of values) is (close to) zero or not
  where "close" means if the absolute value is less than \code{neps*eps}.
  \emph{Note that \code{x == 0} will not work in all cases.}

  By default \code{eps} is the smallest possible floating point value
  that can be represented by the running machine, i.e.
  \code{.Machine$double.eps} and \code{neps} is one.
  By changing \code{neps} it is easy to adjust how close to zero "close"
  means without having to know the machine precision (or remembering how
  to get it).
}

\arguments{
  \item{x}{A \code{\link[base]{vector}} of values.}
  \item{eps}{The smallest possible floating point.}
  \item{neps}{A scale factor of \code{eps} specifying how close to zero
     "close" means. If \code{eps} is the smallest value such that
     \code{1 + eps != 1}, i.e. \code{.Machine$double.eps}, \code{neps} must
     be greater or equal to one.}
  \item{...}{Not used.}
}

\value{Returns a \code{\link[base]{logical}} \code{\link[base]{vector}} indicating if the elements are zero or not.}

\author{Henrik Bengtsson}

\seealso{
  \code{\link[base]{all.equal}}().
  \code{\link[base]{Comparison}}.
  \code{\link[base:zMachine]{.Machine}}.
}

\examples{
x <- 0
print(x == 0)      # TRUE
print(isZero(x))   # TRUE

x <- 1
print(x == 0)      # FALSE
print(isZero(x))   # FALSE

x <- .Machine$double.eps
print(x == 0)      # FALSE
print(isZero(x))   # FALSE

x <- 0.9*.Machine$double.eps
print(x == 0)      # FALSE
print(isZero(x))   # TRUE

# From help(Comparisions)
x1 <- 0.5 - 0.3
x2 <- 0.3 - 0.1
print(x1 - x2)
print(x1 == x2)                           # FALSE on most machines
print(identical(all.equal(x1, x2), TRUE)) # TRUE everywhere
print(isZero(x1-x2))                      # TRUE everywhere
}


\keyword{logic}