Initial revision
[binutils.git] / gas / flonum-copy.c
blob5bcc5cce7e2a09cb8a48f0fffb30a6523fbf0711
1 /* flonum_copy.c - copy a flonum
2 Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #include "as.h"
22 void
23 flonum_copy (in, out)
24 FLONUM_TYPE *in;
25 FLONUM_TYPE *out;
27 unsigned int in_length; /* 0 origin */
28 unsigned int out_length; /* 0 origin */
30 out->sign = in->sign;
31 in_length = in->leader - in->low;
33 if (in->leader < in->low)
35 out->leader = out->low - 1; /* 0.0 case */
37 else
39 out_length = out->high - out->low;
41 * Assume no GAPS in packing of littlenums.
42 * I.e. sizeof(array) == sizeof(element) * number_of_elements.
44 if (in_length <= out_length)
48 * For defensive programming, zero any high-order littlenums we don't need.
49 * This is destroying evidence and wasting time, so why bother???
51 if (in_length < out_length)
53 memset ((char *) (out->low + in_length + 1), '\0', out_length - in_length);
56 memcpy ((void *) (out->low), (void *) (in->low), ((in_length + 1) * sizeof (LITTLENUM_TYPE)));
57 out->exponent = in->exponent;
58 out->leader = in->leader - in->low + out->low;
60 else
62 int shorten; /* 1-origin. Number of littlenums we drop. */
64 shorten = in_length - out_length;
65 /* Assume out_length >= 0 ! */
66 memcpy ((void *) (out->low), (void *) (in->low + shorten), ((out_length + 1) * sizeof (LITTLENUM_TYPE)));
67 out->leader = out->high;
68 out->exponent = in->exponent + shorten;
70 } /* if any significant bits */
71 } /* flonum_copy() */
73 /* end of flonum_copy.c */