![](https://csdnimg.cn/release/download_crawler_static/10469960/bg12.jpg)
2.3.2 Real numbers (t_REAL).
Real numbers are represented (approximately) in a floating point system, internally in base 2,
but converted to base 10 for input / output purposes. A t_REAL object has a given accuracy (or
precision) ` ≥ 0; it comprises
• a sign s: +1, −1 or 0;
• a mantissa m: a multiprecision integer, 0 ≤ m < 10
`
;
• an exponent e: a small integer in [−E, E], where E ≈ 2
B
log
10
2, and B = 32 on a 32-bit
machine and 64 otherwise.
This data may represent any real number x such that
|x − sm10
e
| < 10
e−`
.
We consider that a t_REAL with sign s = 0 has accuracy ` = 0, so that its mantissa is useless, but
it still has an exponent e and acts like a machine epsilon for all accuracies < e.
After an (optional) leading + or -, type a number with a decimal point. Leading zeroes may
be omitted, up to the decimal point, but trailing zeroes are important: your t_REAL is assigned
an internal precision, which is the supremum of the input precision, one more than the number of
decimal digits input, and the default realprecision. For example, if the default precision is 28
digits, typing 2. yields a precision of 28 digits, but 2.0. . . 0 with 45 zeros gives a number with
internal precision at least 45, although less may be printed.
You can also use scientific notation with the letter E or e. As usual, en is interpreted as ×10
n
for all integers n. Since the result is converted to a t_REAL, you may often omit the decimal point
in this case: 6.02 E 23 or 1e-5 are fine, but e10 is not.
By definition, 0.E n returns a real 0 of exponent n, whereas 0. returns a real 0 “of default
precision” (of exponent −realprecision), see Section 1.3.7, behaving like the machine epsilon for
the current default accuracy: any float of smaller absolute value is indistinguishable from 0.
Note on output formats. A zero real number is printed in e format as 0.Exx where xx is the
(usually negative) decimal exponent of the number (cf. Section 1.3.7). This allows the user to check
the accuracy of that particular zero.
When the integer part of a real number x is not known exactly because the exponent of x is
greater than the internal precision, the real number is printed in e format.
Technical note. The internal precision is actually expressed in bits and can be viewed and
manipulated globally in interactive use via realprecision (decimal digits, as explained above;
shortcut \p) or realbitprecision (bits; shortcut \ps), the latter allowing finer granularity. See
Section 3.3 for details. In programs we advise to leave this global variable alone and adapt precision
locally for a given sequence of computations using localbitprec.
2.3.3 Intmods (t_INTMOD). To create the image of the integer a in Z/bZ (for some non-zero
integer b), type Mod(a,b); not a%b. Internally, all operations are done on integer representatives
belonging to [0, b − 1].
Note that this type is available for convenience, not for speed: each elementary operation
involves a reduction modulo b.
If x is a t_INTMOD Mod(a,b), the following member function is defined:
x.mod: return the modulus b.
18