]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/gccint/target-macros/cross-compilation-and-floating-point.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gccint / target-macros / cross-compilation-and-floating-point.rst
CommitLineData
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
10Cross Compilation and Floating Point
11************************************
12
13While all modern machines use twos-complement representation for integers,
14there are a variety of representations for floating point numbers. This
15means that in a cross-compiler the representation of floating point numbers
16in the compiled program may be different from that used in the machine
17doing the compilation.
18
19Because different representation systems may offer different amounts of
20range and precision, all floating point constants must be represented in
21the target machine's format. Therefore, the cross compiler cannot
22safely use the host machine's floating point arithmetic; it must emulate
23the target's arithmetic. To ensure consistency, GCC always uses
24emulation to work with floating point values, even when the host and
25target floating point formats are identical.
26
27The following macros are provided by :samp:`real.h` for the compiler to
28use. All parts of the compiler which generate or optimize
29floating-point calculations must use these macros. They may evaluate
30their 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}`.