This is a binding for the MPFR arbitrary-precision floating point
library.

We define a class RealField, where each instance of
RealField specifies a field of floating-point
numbers with a specified precision and rounding mode. Individual
floating-point numbers are of RealNumber.

Operations in this module which are direct wrappers of MPFR
functions are “correctly rounded”; we briefly describe what this
means. Assume that you could perform the operation exactly, on real
numbers, to get a result \(r\). If this result can be
represented as a floating-point number, then we return that
number.

Otherwise, the result \(r\) is between two floating-point
numbers. For the directed rounding modes (round to plus infinity,
round to minus infinity, round to zero), we return the
floating-point number in the indicated direction from \(r\).
For round to nearest, we return the floating-point number which is
nearest to \(r\).

This leaves one case unspecified: in round to nearest mode, what
happens if \(r\) is exactly halfway between the two nearest
floating-point numbers? In that case, we round to the number with
an even mantissa (the mantissa is the number \(m\) in the
representation above).

Consider the ordered set of floating-point numbers of precision
\(p\). (Here we identify +0 and
-0, and ignore NaN.) We can give a
bijection between these floating-point numbers and a segment of the
integers, where 0 maps to 0 and adjacent floating-point numbers map
to adjacent integers. We call the integer corresponding to a given
floating-point number the “floating-point rank” of the number.
(This is not standard terminology; I just made it up.)

There can be one or two arguments of this init method. If it is one argument,
it must be a hom space. If it is two arguments, it must be two parent structures
that will be domain and codomain of the map-to-be-created.

There can be one or two arguments of this init method. If it is one argument,
it must be a hom space. If it is two arguments, it must be two parent structures
that will be domain and codomain of the map-to-be-created.

prec – (integer) precision; default = 53 prec is
the number of bits used to represent the mantissa of a
floating-point number. The precision can be any integer between
mpfr_prec_min() and mpfr_prec_max(). In the current
implementation, mpfr_prec_min() is equal to 2.

sci_not – (default: False) if True, always display using
scientific notation; if False, display using scientific notation
only for very large or very small numbers

rnd – (string) the rounding mode:

'RNDN' – (default) round to nearest (ties go to the even
number): Knuth says this is the best choice to prevent “floating
point drift”

'RNDD' – round towards minus infinity

'RNDZ' – round towards zero

'RNDU' – round towards plus infinity

EXAMPLES:

sage: RealField(10)Real Field with 10 bits of precisionsage: RealField()Real Field with 53 bits of precisionsage: RealField(100000)Real Field with 100000 bits of precision

The default precision is 53, since according to the MPFR
manual: ‘mpfr should be able to exactly reproduce all
computations with double-precision machine floating-point
numbers (double type in C), except the default exponent range
is much wider and subnormal numbers are not implemented.’

An approximation to the field of real numbers using floating point
numbers with any specified precision. Answers derived from
calculations in this approximation may differ from what they would
be if those calculations were performed in the true field of real
numbers. This is due to the rounding errors inherent to finite
precision calculations.

Return the algebraic closure of self, i.e., the complex field with
the same precision.

EXAMPLES:

sage: RR.algebraic_closure()Complex Field with 53 bits of precisionsage: RR.algebraic_closure()isCCTruesage: RealField(100,rnd='RNDD').algebraic_closure()Complex Field with 100 bits of precisionsage: RealField(100).algebraic_closure()Complex Field with 100 bits of precision

sage: RR.complex_field()Complex Field with 53 bits of precisionsage: RR.complex_field()isCCTruesage: RealField(100,rnd='RNDD').complex_field()Complex Field with 100 bits of precisionsage: RealField(100).complex_field()Complex Field with 100 bits of precision

A floating point approximation to a real number using any specified
precision. Answers derived from calculations with such
approximations may differ from what they would be if those
calculations were performed with true real numbers. This is due to
the rounding errors inherent to finite precision calculations.

The approximation is printed to slightly fewer digits than its
internal precision, in order to avoid confusing roundoff issues
that occur because numbers are stored internally in binary.

The arithmetic-geometric mean is the common limit of the sequences
\(u_n\) and \(v_n\), where \(u_0\) is self,
\(v_0\) is other, \(u_{n+1}\) is the arithmetic mean
of \(u_n\) and \(v_n\), and \(v_{n+1}\) is the
geometric mean of \(u_n\) and \(v_n\). If any operand is negative, the
return value is NaN.

Returns the floating-point rank of this number. That is, if you
list the floating-point numbers of this precision in order, and
number them starting with \(0.0 \rightarrow 0\) and extending
the list to positive and negative infinity, returns the number
corresponding to this floating-point number.

Find a rational near to self. Exactly one of max_error or
max_denominator must be specified.

If max_error is specified, then this returns the simplest rational
in the range [self-max_error..self+max_error]. If
max_denominator is specified, then this returns the rational
closest to self with denominator at most max_denominator.
(In case of ties, we pick the simpler rational.)

Return the simplest rational which is equal to self (in the Sage
sense). Recall that Sage defines the equality operator by coercing
both sides to a single type and then comparing; thus, this finds
the simplest rational which (when coerced to this RealField) is
equal to self.

Given rationals \(a / b\) and \(c / d\) (both in lowest terms), the former
is simpler if \(b < d\) or if \(b = d\) and \(|a| < |c|\).

The effect of rounding modes is slightly counter-intuitive.
Consider the case of round-toward-minus-infinity. This rounding is
performed when coercing a rational to a floating-point number; so
the simplest_rational() of a round-to-minus-infinity number
will be either exactly equal to or slightly larger than the number.

no_sci – if 2, never print using scientific notation; if 1
or True, print using scientific notation only for very large or
very small numbers; if 0 or False always print with scientific
notation; if None (the default), print how the parent prints.

e – symbol used in scientific notation; defaults to ‘e’ for
base=10, and ‘@’ otherwise

truncate – if True, round off the last digits in
printing to lessen confusing base-2 roundoff issues.

Returns the unit of least precision of self, which is the
weight of the least significant bit of self. This is always
a strictly positive number. It is also the gap between this
number and the closest number with larger absolute value that
can be represented.

INPUT:

field – RealField used as parent of the result.
If not specified, use parent(self).

Note

The ulp of zero is defined as the smallest representable
positive number. For extremely small numbers, underflow
occurs and the output is also the smallest representable
positive number (the rounding mode is ignored, this
computation is done by rounding towards +infinity).

Note that the number of bits of precision in the constructor only
effects the internal precision of the pari number, which is rounded
up to the nearest multiple of 32 or 64. To increase the number of
digits that gets displayed you must use
pari.set_real_precision.

There can be one or two arguments of this init method. If it is one argument,
it must be a hom space. If it is two arguments, it must be two parent structures
that will be domain and codomain of the map-to-be-created.

There can be one or two arguments of this init method. If it is one argument,
it must be a hom space. If it is two arguments, it must be two parent structures
that will be domain and codomain of the map-to-be-created.

There can be one or two arguments of this init method. If it is one argument,
it must be a hom space. If it is two arguments, it must be two parent structures
that will be domain and codomain of the map-to-be-created.