format-methods function

Format FLINT-type Numbers as Strings

Format FLINT-type Numbers as Strings

Format a flint vector for pretty printing. methods

## S4 method for signature 'ulong' format(x, base = 10L, ...) ## S4 method for signature 'slong' format(x, base = 10L, ...) ## S4 method for signature 'fmpz' format(x, base = 10L, ...) ## S4 method for signature 'fmpq' format(x, base = 10L, ...) ## S4 method for signature 'mag' format(x, base = 10L, digits = NULL, sep = NULL, rnd = flintRnd(), ...) ## S4 method for signature 'arf' format(x, base = 10L, digits = NULL, sep = NULL, rnd = flintRnd(), ...) ## S4 method for signature 'acf' format(x, base = 10L, digits = NULL, sep = NULL, rnd = flintRnd(), ...) ## S4 method for signature 'arb' format(x, base = 10L, digits = NULL, sep = NULL, rnd = flintRnd(), ...) ## S4 method for signature 'acb' format(x, base = 10L, digits = NULL, sep = NULL, rnd = flintRnd(), ...)

Arguments

  • x: a flint vector.
  • base: an integer from 2 to 62 indicating a base for output. Values 2, 10, and 16 correspond to binary, decimal, and hexadecimal output. Digits are represented by characters [0-9A-Za-z] , in that significance order, hence the maximum 10+26+26=62.
  • digits: an integer indicating how many digits of the significand are reported when formatting floating type vectors. When more than one digit is printed, a radix point inserted after the first digit. Value 0 is equivalent to the minimum integer d such that all elements of x are represented exactly by d digits in the specified base. The default value NULL is equivalent to getOption("digits", 99999L).
  • sep: a nonempty character string used to separate the significand from the exponent. The default value NULL is a equivalent to "e" for base equal to 10 and to "@" for all other bases.
  • rnd: a nonempty character string whose first character indicates a rounding mode. Methods for arb and acb require rnd of length 2, specifying rounding modes separately for midpoints and radii. See flintRnd for information about valid character strings.
  • ...: further optional arguments, though these are currently unused.

Returns

A character vector containing ASCII strings of equal length.

Examples

q <- .fmpq(num = c(-1L, 1L) * 0:5, den = 1:6) for (b in 2:8) { cat("base = ", b, ":\n", sep = "") print(format(q, base = b), quote = FALSE, width = 12L) } z <- .acb(real = .arb(mid = pi, rad = 0.5 * pi)) format(z) format(z, base = 62L, sep = "*[62]^") strsplit(format(Re(z), digits = 80L), "[( )]")[[1L]][c(FALSE, TRUE)]
  • Maintainer: Mikael Jagan
  • License: GPL (>= 2)
  • Last published: 2025-03-24