Learn R Programming

flint (version 0.0.3)

fmpq-class: Arbitrary Precision Rational Numbers

Description

Class fmpq extends virtual class flint. It represents vectors of arbitrary precision rational numbers. Elements are specified by a pair of arbitrary precision signed integers: a numerator and a positive, coprime denominator. There is no representation for R's missing value NA_integer_.

Usage

## The class generator function:
.fmpq(...)

## Mode 1: initialize with zeros ## .fmpq(length = 0L) ## ## Mode 2: initialize with vector ## .fmpq(length = length(x), x) ## ## Mode 3: initialize by parts ## .fmpq(length = max0(length(num), length(den)), num, den) ## ## where max0 <- function(m, n) if (min(m, n)) max(m, n) else 0L

Value

The class generator function returns new("fmpq", ...).

Arguments

...

arguments passed to methods for initialize.

Slots

.xData, names

inherited from virtual class flint.

Methods

!

signature(x = "fmpq"):
equivalent to (but faster than) x == 0.

+

signature(e1 = "fmpq", e2 = "missing"):
returns a copy of the argument.

-

signature(e1 = "fmpq", e2 = "missing"):
returns the negation of the argument.

Complex

signature(z = "fmpq"):
mathematical functions of one argument; see S4groupGeneric. Member functions requiring promotion to a floating-point type may not be implemented.

Math

signature(x = "fmpq"):
mathematical functions of one argument; see S4groupGeneric. Member functions requiring promotion to a floating-point type may not be implemented.

Math2

signature(x = "fmpq"):
decimal rounding according to a second argument digits; see S4groupGeneric. There are just two member member functions: round, signif.

Ops

signature(e1 = "ANY", e2 = "fmpq"):
signature(e1 = "fmpq", e2 = "ANY"):
binary arithmetic, comparison, and logical operators; see S4groupGeneric. The “other” operand must be atomic or inherit from virtual class flint. The operands are recycled and promoted as necessary.

Summary

signature(x = "fmpq"):
univariate summary statistics; see S4groupGeneric. The return value is a logical vector of length 1 (any, all) or an fmpq vector of length 1 or 2 (sum, prod, min, max, range).

anyNA

signature(x = "fmpq"):
returns FALSE, as fmpq has no representation for NaN.

as.vector

signature(x = "fmpq"):
returns as.vector(y, mode), where y is a double vector containing the result of converting each element of x to the range of double, rounding if the value is not exactly representable in double precision. The rounding mode is to the nearest representable number in the direction of zero, unless the element exceeds .Machine[["double.xmax"]] in absolute value, in which case -Inf or Inf is introduced with a warning. Coercion to types "character", "symbol" (synonym "name"), "pairlist", "list", and "expression", which are not “number-like”, is handled specially.

coerce

signature(from = "ANY", to = "fmpq"):
returns .fmpq(x = from). An error is signaled if the class or type of from is not supported by the method for initialize.

format

signature(x = "fmpq"):
returns a character vector suitable for printing, using string format "p/q". Optional arguments control the output; see format-methods.

initialize

signature(.Object = "fmpq", length = "numeric"):
returns .Object after setting its .xData slot. The new slot value is an external pointer to an array of the corresponding C type, which is newly allocated and initialized entirely with zeros (zero numerator, unit denominator). .Object is not copied, so all references are affected.

initialize

signature(.Object = "fmpq", length = "numeric", x = "atomic|flint"):
as above, except that the new slot value points to an array initialized with values from x. An error is signaled if elements of x are NaN, -Inf, or Inf.

initialize

signature(.Object = "fmpq", length = "numeric", num = "atomic|flint", den = "atomic|flint"):
as above, except that the new slot value points to an array whose numerators and denominators are initialized separately with values from num and den, which are coerced to class fmpz and recycled as necessary. An error is signaled if elements of num or den are NaN, -Inf, or Inf or elements of den are zero.

is.finite

signature(x = "fmpq"):
returns a logical vector whose elements are all TRUE, as fmpq has no representation for NaN, -Inf, and Inf.

is.infinite, is.na, is.nan

signature(x = "fmpq"):
returns a logical vector whose elements are all FALSE, as fmpq has no representation for NaN, -Inf, and Inf.

is.unsorted

signature(x = "fmpq"):
returns a logical indicating if x is not sorted in nondecreasing order (increasing order if optional argument strictly is set to TRUE).

mean

signature(x = "fmpq"):
returns the arithmetic mean. An error is signaled if the argument length is 0, because the return type is fmpq which cannot represent the result of division by 0.

References

The FLINT documentation of the underlying C type: https://flintlib.org/doc/fmpq.html

See Also

Virtual class flint. Generic functions Num and Den and their replacement forms for getting and setting numerators and denominators.

Examples

Run this code
showClass("fmpq")
showMethods(classes = "fmpq")

Run the code above in your browser using DataLab