bignum-format {bignum}R Documentation

Format a bignum vector

Description

Customize how a biginteger or bigfloat vector is displayed. The precision can be controlled with a number of significant figures, or with a maximum or fixed number of digits after the decimal point. You can also choose between decimal, scientific and hexadecimal notations.

The default formatting applied when printing depends on the type of object:

Usage

## S3 method for class 'bignum_biginteger'
format(
  x,
  ...,
  sigfig = NULL,
  digits = NULL,
  notation = c("fit", "dec", "sci", "hex")
)

## S3 method for class 'bignum_bigfloat'
format(x, ..., sigfig = NULL, digits = NULL, notation = c("fit", "dec", "sci"))

Arguments

x

A biginteger or bigfloat vector.

...

These dots are for future extensions and must be empty.

sigfig

Number of significant figures to show. Must be positive. Cannot be combined with digits.

If both sigfig and digits are unspecified, then consults the "bignum.sigfig" option (default: 7).

digits

Number of digits to show after the decimal point. Positive values indicate the exact number of digits to show. Negative values indicate the maximum number of digits to show (terminal zeros are hidden if there are no subsequent non-zero digits). Cannot be combined with sigfig.

notation

How should the vector be displayed? Choices:

  • "fit": Use decimal notation if it fits, otherwise use scientific notation. Consults the "bignum.max_dec_width" option (default: 13).

  • "dec": Use decimal notation, regardless of width.

  • "sci": Use scientific notation.

  • "hex": Use hexadecimal notation (positive biginteger only).

Value

Character vector

Examples

# default uses decimal notation
format(bigfloat(1e12))

# until it becomes too wide, then it uses scientific notation
format(bigfloat(1e13))

# hexadecimal notation is supported for positive integers
format(biginteger(255), notation = "hex")

# significant figures
format(bigfloat(12.5), sigfig = 2)

# fixed digits after decimal point
format(bigfloat(12.5), digits = 2)

# maximum digits after decimal point
format(bigfloat(12.5), digits = -2)

[Package bignum version 0.3.2 Index]