flonum-copy.c revision 1.10 1 1.1 christos /* flonum_copy.c - copy a flonum
2 1.10 christos Copyright (C) 1987-2025 Free Software Foundation, Inc.
3 1.1 christos
4 1.1 christos This file is part of GAS, the GNU Assembler.
5 1.1 christos
6 1.1 christos GAS is free software; you can redistribute it and/or modify
7 1.1 christos it under the terms of the GNU General Public License as published by
8 1.1 christos the Free Software Foundation; either version 3, or (at your option)
9 1.1 christos any later version.
10 1.1 christos
11 1.1 christos GAS is distributed in the hope that it will be useful,
12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 1.1 christos GNU General Public License for more details.
15 1.1 christos
16 1.1 christos You should have received a copy of the GNU General Public License
17 1.1 christos along with GAS; see the file COPYING. If not, write to the Free
18 1.1 christos Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 1.1 christos 02110-1301, USA. */
20 1.1 christos
21 1.1 christos #include "as.h"
22 1.1 christos
23 1.1 christos void
24 1.1 christos flonum_copy (FLONUM_TYPE *in, FLONUM_TYPE *out)
25 1.1 christos {
26 1.1 christos unsigned int in_length; /* 0 origin */
27 1.1 christos unsigned int out_length; /* 0 origin */
28 1.1 christos
29 1.1 christos out->sign = in->sign;
30 1.1 christos in_length = in->leader - in->low;
31 1.1 christos
32 1.1 christos if (in->leader < in->low)
33 1.1 christos {
34 1.1 christos out->leader = out->low - 1; /* 0.0 case */
35 1.1 christos }
36 1.1 christos else
37 1.1 christos {
38 1.1 christos out_length = out->high - out->low;
39 1.1 christos /* Assume no GAPS in packing of littlenums.
40 1.1 christos I.e. sizeof(array) == sizeof(element) * number_of_elements. */
41 1.1 christos if (in_length <= out_length)
42 1.1 christos {
43 1.1 christos {
44 1.1 christos /* For defensive programming, zero any high-order
45 1.1 christos littlenums we don't need. This is destroying evidence
46 1.1 christos and wasting time, so why bother??? */
47 1.1 christos if (in_length < out_length)
48 1.1 christos {
49 1.10 christos memset (out->low + in_length + 1, 0, out_length - in_length);
50 1.1 christos }
51 1.1 christos }
52 1.10 christos memcpy (out->low, in->low,
53 1.10 christos (in_length + 1) * sizeof (LITTLENUM_TYPE));
54 1.1 christos out->exponent = in->exponent;
55 1.1 christos out->leader = in->leader - in->low + out->low;
56 1.1 christos }
57 1.1 christos else
58 1.1 christos {
59 1.1 christos int shorten; /* 1-origin. Number of littlenums we drop. */
60 1.1 christos
61 1.1 christos shorten = in_length - out_length;
62 1.1 christos /* Assume out_length >= 0 ! */
63 1.10 christos memcpy (out->low, in->low + shorten,
64 1.10 christos (out_length + 1) * sizeof (LITTLENUM_TYPE));
65 1.1 christos out->leader = out->high;
66 1.1 christos out->exponent = in->exponent + shorten;
67 1.1 christos }
68 1.1 christos } /* if any significant bits */
69 1.1 christos }
70