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