]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/target-float.c
Target FP: Introduce target-float.{c,h}
[thirdparty/binutils-gdb.git] / gdb / target-float.c
1 /* Floating point routines for GDB, the GNU debugger.
2
3 Copyright (C) 2017 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "dfp.h"
22 #include "doublest.h"
23 #include "gdbtypes.h"
24 #include "floatformat.h"
25 #include "target-float.h"
26
27
28 /* Typed floating-point routines. These routines operate on floating-point
29 values in target format, represented by a byte buffer interpreted as a
30 "struct type", which may be either a binary or decimal floating-point
31 type (TYPE_CODE_FLT or TYPE_CODE_DECFLOAT). */
32
33 /* Return whether the byte-stream ADDR holds a valid value of
34 floating-point type TYPE. */
35 bool
36 target_float_is_valid (const gdb_byte *addr, const struct type *type)
37 {
38 if (TYPE_CODE (type) == TYPE_CODE_FLT)
39 return floatformat_is_valid (floatformat_from_type (type), addr);
40
41 if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
42 return true;
43
44 gdb_assert_not_reached ("unexpected type code");
45 }
46
47 /* Return whether the byte-stream ADDR, interpreted as floating-point
48 type TYPE, is numerically equal to zero (of either sign). */
49 bool
50 target_float_is_zero (const gdb_byte *addr, const struct type *type)
51 {
52 if (TYPE_CODE (type) == TYPE_CODE_FLT)
53 return (floatformat_classify (floatformat_from_type (type), addr)
54 == float_zero);
55
56 if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
57 return decimal_is_zero (addr, TYPE_LENGTH (type),
58 gdbarch_byte_order (get_type_arch (type)));
59
60 gdb_assert_not_reached ("unexpected type code");
61 }
62