Rational Transformations

# S4 method for rationalS4
as.numeric(x, ...)

# S4 method for rationalS4
as.integer(x, ...)

# S4 method for rationalS4
as.character(x, ...)

as.rationalS4(x, cycles = 10, max.denominator = 2000)

# S4 method for numeric
as.rationalS4(x, cycles = 10,
  max.denominator = 2000)

# S4 method for character
as.rationalS4(x, cycles = 10,
  max.denominator = 2000)

as.rationalS3(x, cycles = 10, max.denominator = 2000)

# S3 method for rationalS3
as.double(x, ...)

# S3 method for rationalS3
as.integer(x, ...)

as.rationalR6(x, cycles = 10, max.denominator = 2000)

# S3 method for rationalR6
as.double(x, ...)

# S3 method for rationalR6
as.integer(x, ...)

Arguments

x

parameter to be transformed between classes

...

additional parameters passed to underlying methods

cycles

The maximum number of steps to be used in the continued fraction approximation process

max.denominator

If the denominator exceeds this number, the algorithm will stop with an approximation

Examples

as.numeric(rational(c(2L, 3L), c(5L, 1L), "S4"))
#> [1] 0.4 3.0
as.integer(rational(c(2L, 3L), c(5L, 1L), "S4"))
#> [1] 0 3
as.integer(rational(8L, 3L, "S4"))
#> [1] 2
as.character(rational(c(2L, 3L), c(5L, 1L), "S4"))
#> [1] "2 / 5" "3 / 1"
as.rationalS4(33.3)
#> (333 / 10) = 33.3
as.rationalS4("33.3")
#> (333 / 10) = 33.3
as.rationalS3(33.3)
#> [1] "(333 / 10) = 33.3"
as.rationalS3(c(33.3, 3.3))
#> [1] "(333 / 10) = 33.3" "(33 / 10) = 3.3"
as.double(rational(1L, 3L, "S3"))
#> [1] 0.3333333
as.double(rational(c(1L, 2L), c(3L, 5L), "S3"))
#> [1] 0.3333333 0.4000000
as.numeric(rational(1L, 3L, "S3"))
#> [1] 0.3333333
as.numeric(rational(c(1L, 2L), c(3L, 5L), "S3"))
#> [1] 0.3333333 0.4000000
as.integer(rational(1L, 3L, "S3"))
#> [1] 0
as.integer(rational(c(1L, 2L), c(3L, 5L), "S3"))
#> [1] 0 0
as.rationalR6(33.3)
#> [1] "(333 / 10) = 33.3"
as.rationalR6(c(33.3, 3.3))
#> [1] "(333 / 10) = 33.3" "(33 / 10) = 3.3"
as.double(rational(1L, 3L, "S3"))
#> [1] 0.3333333
as.double(rational(c(1L, 2L), c(3L, 5L), "S3"))
#> [1] 0.3333333 0.4000000
as.numeric(rational(1L, 3L, "S3"))
#> [1] 0.3333333
as.numeric(rational(c(1L, 2L), c(3L, 5L), "S3"))
#> [1] 0.3333333 0.4000000
as.integer(rational(1L, 3L, "S3"))
#> [1] 0
as.integer(rational(c(1L, 2L), c(3L, 5L), "S3"))
#> [1] 0 0