4.3.2 sage.rings.real_number - Real number

Real numbers in SAGE are represented either as GMP MPF's or using the Python Decimal type.

The module sage.rings.real_number defines the following classes:

class RealNumber
Abstract real number base class.

class RealNumber_decimal
A real number with an arbitrary number of bits of precision. This is implemented using the builtin Python Decimal type.

Create a number using RealNumber_decimal(value,)

INPUT: value - a float, integer, or string

sage: R = real_number.RealNumber_decimal
sage: R(1.32)
1.32
sage: R('2/3')
0.6666666666666666666666666667
sage: x = R(1.234); y = R(-1.1)
sage: x < y
False
sage: x > y
True
sage: x + y
0.134
sage: x - y
2.334
sage: x * y
-1.3574
sage: x / y
-1.121818181818181818181818182
sage: x*100
123.400
sage: x**100
1353679866.791074518495392801
sage: 2*x
2.468
sage: x*2.0
2.4680
sage: x.order()
Infinity
sage: x.prec()
Infinity
sage: float(x)
1.234
sage: int(y)
-1

class RealNumber_mpf
A real number with a fixed number of bits of precision.

Create a number using RealNumber_mpf(value, bits=0)

INPUT: value - a float, integer, or string prec - an int, lower bound on the number of bits of precision (always >= 64).

sage: R = real_number.RealNumber_mpf
sage: x = R(1.234); y = R(-1.1)
sage: x < y
False
sage: x > y
True
sage: x + y
0.133999999999999896971
sage: x - y
2.33400000000000007461
sage: x * y
-1.35740000000000009397
sage: x / y
-1.12181818181818171468
sage: x*100
123.399999999999998579
sage: x**100
1.35367986679107295756e9
sage: 2*x
2.46799999999999997158
sage: x*2.0
2.46799999999999997158
sage: x.order()
Infinity
sage: x.prec()
64
sage: float(x)
1.234
sage: int(y)
-1



Subsections
See About this document... for information on suggesting changes.