]>
Commit | Line | Data |
---|---|---|
c63539ff ML |
1 | .. |
2 | Copyright 1988-2022 Free Software Foundation, Inc. | |
3 | This is part of the GCC manual. | |
4 | For copying conditions, see the copyright.rst file. | |
5 | ||
6 | .. index:: cross compilation and floating point, floating point and cross compilation | |
7 | ||
8 | .. _floating-point: | |
9 | ||
10 | Cross Compilation and Floating Point | |
11 | ************************************ | |
12 | ||
13 | While all modern machines use twos-complement representation for integers, | |
14 | there are a variety of representations for floating point numbers. This | |
15 | means that in a cross-compiler the representation of floating point numbers | |
16 | in the compiled program may be different from that used in the machine | |
17 | doing the compilation. | |
18 | ||
19 | Because different representation systems may offer different amounts of | |
20 | range and precision, all floating point constants must be represented in | |
21 | the target machine's format. Therefore, the cross compiler cannot | |
22 | safely use the host machine's floating point arithmetic; it must emulate | |
23 | the target's arithmetic. To ensure consistency, GCC always uses | |
24 | emulation to work with floating point values, even when the host and | |
25 | target floating point formats are identical. | |
26 | ||
27 | The following macros are provided by :samp:`real.h` for the compiler to | |
28 | use. All parts of the compiler which generate or optimize | |
29 | floating-point calculations must use these macros. They may evaluate | |
30 | their operands more than once, so operands must not have side effects. | |
31 | ||
32 | .. c:macro:: REAL_VALUE_TYPE | |
33 | ||
34 | The C data type to be used to hold a floating point value in the target | |
35 | machine's format. Typically this is a ``struct`` containing an | |
36 | array of ``HOST_WIDE_INT``, but all code should treat it as an opaque | |
37 | quantity. | |
38 | ||
39 | .. function:: HOST_WIDE_INT REAL_VALUE_FIX (REAL_VALUE_TYPE x) | |
40 | ||
41 | Truncates :samp:`{x}` to a signed integer, rounding toward zero. | |
42 | ||
43 | .. function:: unsigned HOST_WIDE_INT REAL_VALUE_UNSIGNED_FIX (REAL_VALUE_TYPE x) | |
44 | ||
45 | Truncates :samp:`{x}` to an unsigned integer, rounding toward zero. If | |
46 | :samp:`{x}` is negative, returns zero. | |
47 | ||
48 | .. function:: REAL_VALUE_TYPE REAL_VALUE_ATOF (const char *string, machine_mode mode) | |
49 | ||
50 | Converts :samp:`{string}` into a floating point number in the target machine's | |
51 | representation for mode :samp:`{mode}`. This routine can handle both | |
52 | decimal and hexadecimal floating point constants, using the syntax | |
53 | defined by the C language for both. | |
54 | ||
55 | .. function:: int REAL_VALUE_NEGATIVE (REAL_VALUE_TYPE x) | |
56 | ||
57 | Returns 1 if :samp:`{x}` is negative (including negative zero), 0 otherwise. | |
58 | ||
59 | .. function:: int REAL_VALUE_ISINF (REAL_VALUE_TYPE x) | |
60 | ||
61 | Determines whether :samp:`{x}` represents infinity (positive or negative). | |
62 | ||
63 | .. function:: int REAL_VALUE_ISNAN (REAL_VALUE_TYPE x) | |
64 | ||
65 | Determines whether :samp:`{x}` represents a 'NaN' (not-a-number). | |
66 | ||
67 | .. function:: REAL_VALUE_TYPE REAL_VALUE_NEGATE (REAL_VALUE_TYPE x) | |
68 | ||
69 | Returns the negative of the floating point value :samp:`{x}`. | |
70 | ||
71 | .. function:: REAL_VALUE_TYPE REAL_VALUE_ABS (REAL_VALUE_TYPE x) | |
72 | ||
3ed1b4ce | 73 | Returns the absolute value of :samp:`{x}`. |