next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc :: RR

RR -- the class of all real numbers

Description

A real number is entered as a sequence of decimal digits with a point. It is stored internally as an arbitrary precision floating point number, using the MPFR library.
i1 : 3.14159

o1 = 3.14159

o1 : RR (of precision 53)
The precision is measured in bits, is visible in the ring displayed on the second of each pair of output lines, and can be recovered using precision.
i2 : precision 3.14159

o2 = 53
For real numbers, the functions class and ring yield different results. That allows numbers of various precisions to be used without creating a new ring for each precision.
i3 : class 3.1

o3 = RR

o3 : InexactFieldFamily
i4 : ring 3.1

o4 = RR
       53

o4 : RealField
The precision can be specified on input by appending the letter p and a positive number.
i5 : 3p300

o5 = 3

o5 : RR (of precision 300)
An optional exponent (for the power of ten to multiply by) can be specified on input by appending the letter e and a number.
i6 : 3e3

o6 = 3000

o6 : RR (of precision 53)
i7 : -3e-3

o7 = -.003

o7 : RR (of precision 53)
i8 : -3p111e-3

o8 = -.003

o8 : RR (of precision 111)
Numbers that appear alone on an output line are displayed with all their meaningful digits. (Specifying 100 bits of precision yields about 30 decimal digits of precision.)
i9 : 1/3.

o9 = .333333333333333

o9 : RR (of precision 53)
i10 : 1/3p100

o10 = .333333333333333333333333333333

o10 : RR (of precision 100)
i11 : 100 * log(10,2)

o11 = 30.1029995663981

o11 : RR (of precision 53)
Numbers displayed inside more complicated objects are printed with the number of digits specified by printingPrecision.
i12 : printingPrecision

o12 = 6
i13 : {1/3.,1/3p100}

o13 = {.333333, .333333}

o13 : List
The notion of equality tested by == amounts to equality of the internal binary digits.
i14 : .5p100 == .5p30

o14 = true
i15 : .2p100 == .2p30

o15 = false
The notion of (strict) equality tested by === also takes the precision into account.
i16 : .5p100 === .5p30

o16 = false
i17 : .2p100 === .2p30

o17 = false
Perhaps surprisingly, the IEEE floating point standard also specifies that every number, including 0, has a sign bit, and strict equality testing takes it into account, as it must do, because some arithmetic and transcendental functions take it into account.
i18 : 0.

o18 = 0

o18 : RR (of precision 53)
i19 : -0.

o19 = -0

o19 : RR (of precision 53)
i20 : 1/0.

o20 = infinity

o20 : RR (of precision 53)
i21 : 1/-0.

o21 = -infinity

o21 : RR (of precision 53)
i22 : log 0

o22 = -infinity

o22 : RR (of precision 53)
i23 : csc (0.)

o23 = infinity

o23 : RR (of precision 53)
i24 : csc (-0.)

o24 = -infinity

o24 : RR (of precision 53)
Use toExternalString to produce something that, when encountered as input, will reproduce exactly what you had before.
i25 : x = {1/3.,1/3p100}

o25 = {.333333, .333333}

o25 : List
i26 : x == {.333333, .333333}

o26 = false
i27 : y = toExternalString x

o27 = {.33333333333333331p53,.33333333333333333333333333333346p100}
i28 : x === value y

o28 = true
Transcendental constants and functions are available to high precision, with numeric.
i29 : numeric pi

o29 = 3.14159265358979

o29 : RR (of precision 53)
i30 : numeric_200 pi

o30 = 3.14159265358979323846264338327950288419716939937510582097494

o30 : RR (of precision 200)
i31 : Gamma oo

o31 = 2.28803779534003241795958890906023392288968815335622244119938

o31 : RR (of precision 200)

See also

Functions and methods returning a real number :

Methods that use a real number :

For the programmer

The object RR is an inexact field family, with ancestor classes InexactNumber < Number < Thing.