File: mod.R

package info (click to toggle)
r-cran-matlab 1.0.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 640 kB
  • sloc: sh: 13; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (2)
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
###
### $Id: mod.R 22 2022-05-30 18:03:47Z proebuck $
###


##-----------------------------------------------------------------------------
test.mod <- function(input, expected) {
    output <- do.call(getFromNamespace("mod", "matlab"), input)
    identical(output, expected)
}

mod.expected.scalar <- 3
mod.expected.vec <- c(1, 2, 0, 1, 2)

test.mod(list(x = 13, y = 5), mod.expected.scalar)
test.mod(list(x = 1:5, y = 3), mod.expected.vec)

## by convention
any.nonzero <- 1
test.mod(list(x = any.nonzero, y = 0), any.nonzero)   ## HWB 2011/03/08
test.mod(list(x = any.nonzero, y = any.nonzero), 0)

## get complicated
test.mod(list(x = 5, y = c(1, 2, 0, NaN, Inf)), c(0, 1, 5, NaN, NaN))
test.mod(list(x = 1:5, y = c(1, 2, 0, NaN, Inf)), c(0, 0, 3, NaN, NaN))

## rem & mod give same results with X, Y having same sign
test.mod(list(x = 5, y = 3), matlab::rem(5, 3))
test.mod(list(x = -5, y = -3), matlab::rem(-5, -3))

## alternate formula used when X, Y having different signs
test.mod(list(x = 5, y = -3), (matlab::rem(5, -3) - -3))
test.mod(list(x = -5, y = 3), (matlab::rem(-5, 3) - 3))