ial issue is signed zeroes: on IEC 60559 platforms there are two
zeroes with internal representations differing by sign. Where possible  R
treats them as the same, but for example direct output from C code often does
not do so and may output  -0.0  (and on Windows whether it does so or not
depends on the version of Windows). One place in  R  where the difference
might be seen is in division by zero: ` 1/x ` is ` Inf ` or ` -Inf ` depending
on the sign of zero ` x ` . Another place is ` [ identical
](/link/identical?package=base&version=3.6.2) (0, -0, num.eq = FALSE) ` .

##  Details

The unary and binary arithmetic operators are generic functions: methods can
be written for them individually or via the ` [ Ops
](/link/Ops?package=base&version=3.6.2&to=%3DS3groupGeneric) ` group generic
function. (See ` [ Ops
](/link/Ops?package=base&version=3.6.2&to=%3DS3groupGeneric) ` for how
dispatch is computed.)

If applied to arrays the result will be an array if this is sensible (for
example it will not if the recycling rule has been invoked).

Logical vectors will be coerced to integer or numeric vectors, ` FALSE `
having value zero and ` TRUE ` having value one.

` 1 ^ y ` and ` y ^ 0 ` are ` 1 ` , _always_ . ` x ^ y ` should also give the
proper limit result when either (numeric) argument is [ infinite
](/link/infinite?package=base&version=3.6.2) (one of ` Inf ` or ` -Inf ` ).

Objects such as arrays or time-series can be operated on this way provided
they are conformable.

For double arguments, ` %% ` can be subject to catastrophic loss of accuracy
if ` x ` is much larger than ` y ` , and a warning is given if this is
detected.

` %% ` and ` x %/% y ` can be used for non-integer ` y ` , e.g. ` 1 %/% 0.2 `
, but the results are subject to representation error and so may be platform-
dependent. Because the IEC 60559 representation of ` 0.2 ` is a binary
fraction slightly larger than ` 0.2 ` , the answer to ` 1 %/% 0.2 ` should be
` 4 ` but most platforms give ` 5 ` .

Users are sometimes surprised by the value returned, for example why `
(-8)^(1/3) ` is ` NaN ` . For [ double
](/link/double?package=base&version=3.6.2) inputs,  R  makes use of IEC 60559
arithmetic on all platforms, together with the C system function  pow  for the
` ^ ` operator. The relevant standards define the result in many corner cases.
In particular, the result in the example above is mandated by the C99
standard. On many Unix-alike systems the command ` man pow ` gives details of
the values in a large number of corner cases.

Arithmetic on type [ double ](/link/double?package=base&version=3.6.2) in  R
is supposed to be done in ‘round to nearest, ties to even’ mode, but this does
depend on the compiler and FPU being set up correctly.

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

D. Goldberg (1991). What Every Computer Scientist Should Know about Floating-
Point Arithmetic. _ACM Computing Surveys_ , **23** (1), 5--48.
10.1145/103162.103163.

Postscript version available at [ http://www.validlab.com/goldberg/paper.ps
](http://www.validlab.com/goldberg/paper.ps) . Extended PDF version at [
http://www.validlab.com/goldberg/paper.pdf
](http://www.validlab.com/goldberg/paper.pdf) .

For the IEC 60559 (aka IEEE 754) standard: [
https://www.iso.org/standard/57469.html
](https://www.iso.org/standard/57469.html) and [
https://en.wikipedia.org/wiki/IEEE_754
](https://en.wikipedia.org/wiki/IEEE_754) .

##  See Also

` [ sqrt ](/link/sqrt?package=base&version=3.6.2) ` for miscellaneous and ` [
Special ](/link/Special?package=base&version=3.6.2) ` for special mathematical
functions.

` [ Syntax ](/link/Syntax?package=base&version=3.6.2) ` for operator
precedence.

` [ %*% ](/link/%25*%25?package=base&version=3.6.2) ` for matrix
multiplication.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2FArithmetic&utm_sour