# Rで四則演算　Rで数学の色々をいじってみる

• 四則演算と剰余 four arithmetic operations and residue
```5+3
5-3
5*3
5/3
5^3
5%%3 # 剰余 residue
5%/%3 # 商 quotient 5 = 5 * (5%/%3) +5%%3
3 * (5%/%3) +5%%3
help(Arithmetic)
help(Syntax)
```
• 四捨五入、切り上げ、切り捨て round-off, round-up, round-down
```> pi
[1] 3.141593
> floor(pi)
[1] 3
> round(pi)
[1] 3
> ceiling(pi)
[1] 4
> floor(pi)
[1] 3
> round(pi,0)
[1] 3
> round(pi,1)
[1] 3.1
> round(pi,2)
[1] 3.14
> round(pi,0:10) # 桁 0,1,2,...,10をそれぞれ実施
[1] 3.000000 3.100000 3.140000 3.142000 3.141600 3.141590 3.141593
[8] 3.141593 3.141593 3.141593 3.141593
```
• 有効桁数のデフォルトは７桁(らしい)
```> options(digits=22) # 22が設定限界(らしい)
> round(pi,0:10)
[1] 3.000000000000000000000 3.100000000000000088818
[3] 3.140000000000000124345 3.141999999999999904077
[5] 3.141599999999999948130 3.141589999999999882618
[7] 3.141592999999999857863 3.141592699999999904747
[9] 3.141592650000000208621 3.141592654000000095493
[11] 3.141592653600000062397
> options(digits=7)
```

http://ofmind.net/doc/r-intro-lecture#PRECEDENCE