R Under development (unstable) (2023-12-13 r85679 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > library(rcdd) If you want correct answers, use rational arithmetic. See the Warnings sections in help pages for functions that do computational geometry. > > set.seed(42) > x <- matrix(runif(4), 2, 2) > print(x) [,1] [,2] [1,] 0.9148060 0.2861395 [2,] 0.9370754 0.8304476 > > y <- d2q(x) > print(y) [,1] [,2] [1,] "3929062039/4294967296" "153619993/536870912" [2,] "2012354127/2147483648" "3566745395/4294967296" > > xfoo <- x > attr(xfoo, "blurfle") <- "woof!" > class(xfoo) <- c("foo", "bar", "baz") > yfoo <- d2q(xfoo) > print(yfoo) [,1] [,2] [1,] "3929062039/4294967296" "153619993/536870912" [2,] "2012354127/2147483648" "3566745395/4294967296" attr(,"blurfle") [1] "woof!" attr(,"class") [1] "foo" "bar" "baz" > > z <- q2d(y) > print(z) [,1] [,2] [1,] 0.9148060 0.2861395 [2,] 0.9370754 0.8304476 > > x - z [,1] [,2] [1,] 0 0 [2,] 0 0 > > foo <- d2q(0.5) > print(foo) [1] "1/2" > bar <- q2q(foo) > print(bar) [1] "1/2" > bar[1] <- "-15/3" > baz <- q2q(bar) > print(baz) [1] "-5" > > numer <- as.character(seq(-3, 3)) > denom <- as.character(seq(along = numer)) > qux <- z2q(numer, denom) > print(qux) [1] "-3" "-1" "-1/3" "0" "1/5" "1/3" "3/7" > > numer <- seq(-3, 3) > denom <- seq(along = numer) > qux <- z2q(numer, denom) > print(qux) [1] "-3" "-1" "-1/3" "0" "1/5" "1/3" "3/7" > > qux <- z2q(numer, denom, canonicalize = FALSE) > print(qux) [1] "-3/1" "-2/2" "-1/3" "0/4" "1/5" "2/6" "3/7" > > > proc.time() user system elapsed 0.14 0.04 0.17