Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* flonum_copy.c - copy a flonum |
aa820537 | 2 | Copyright 1987, 1990, 1991, 1992, 1993, 2000, 2003, 2005, 2007 |
f7e42eb4 | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | |
5 | This file is part of GAS, the GNU Assembler. | |
6 | ||
7 | GAS is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 9 | the Free Software Foundation; either version 3, or (at your option) |
252b5132 RH |
10 | any later version. |
11 | ||
12 | GAS 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 | |
b041f888 | 18 | along with GAS; see the file COPYING. If not, write to the Free |
4b4da160 NC |
19 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
20 | 02110-1301, USA. */ | |
252b5132 RH |
21 | |
22 | #include "as.h" | |
23 | ||
24 | void | |
dd625418 | 25 | flonum_copy (FLONUM_TYPE *in, FLONUM_TYPE *out) |
252b5132 | 26 | { |
b041f888 KH |
27 | unsigned int in_length; /* 0 origin */ |
28 | unsigned int out_length; /* 0 origin */ | |
252b5132 RH |
29 | |
30 | out->sign = in->sign; | |
31 | in_length = in->leader - in->low; | |
32 | ||
33 | if (in->leader < in->low) | |
34 | { | |
35 | out->leader = out->low - 1; /* 0.0 case */ | |
36 | } | |
37 | else | |
38 | { | |
39 | out_length = out->high - out->low; | |
b041f888 KH |
40 | /* Assume no GAPS in packing of littlenums. |
41 | I.e. sizeof(array) == sizeof(element) * number_of_elements. */ | |
252b5132 RH |
42 | if (in_length <= out_length) |
43 | { | |
44 | { | |
b041f888 KH |
45 | /* For defensive programming, zero any high-order |
46 | littlenums we don't need. This is destroying evidence | |
47 | and wasting time, so why bother??? */ | |
252b5132 RH |
48 | if (in_length < out_length) |
49 | { | |
b041f888 KH |
50 | memset ((char *) (out->low + in_length + 1), '\0', |
51 | out_length - in_length); | |
252b5132 RH |
52 | } |
53 | } | |
b041f888 KH |
54 | memcpy ((void *) (out->low), (void *) (in->low), |
55 | ((in_length + 1) * sizeof (LITTLENUM_TYPE))); | |
252b5132 RH |
56 | out->exponent = in->exponent; |
57 | out->leader = in->leader - in->low + out->low; | |
58 | } | |
59 | else | |
60 | { | |
f0e652b4 | 61 | int shorten; /* 1-origin. Number of littlenums we drop. */ |
252b5132 RH |
62 | |
63 | shorten = in_length - out_length; | |
64 | /* Assume out_length >= 0 ! */ | |
b041f888 KH |
65 | memcpy ((void *) (out->low), (void *) (in->low + shorten), |
66 | ((out_length + 1) * sizeof (LITTLENUM_TYPE))); | |
252b5132 RH |
67 | out->leader = out->high; |
68 | out->exponent = in->exponent + shorten; | |
69 | } | |
70 | } /* if any significant bits */ | |
b041f888 | 71 | } |