]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/flonum-copy.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gas / flonum-copy.c
CommitLineData
252b5132 1/* flonum_copy.c - copy a flonum
d87bef3a 2 Copyright (C) 1987-2023 Free Software Foundation, Inc.
252b5132
RH
3
4 This file is part of GAS, the GNU Assembler.
5
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
ec2655a6 8 the Free Software Foundation; either version 3, or (at your option)
252b5132
RH
9 any later version.
10
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.
15
16 You should have received a copy of the GNU General Public License
b041f888 17 along with GAS; see the file COPYING. If not, write to the Free
4b4da160
NC
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
252b5132
RH
20
21#include "as.h"
22
23void
dd625418 24flonum_copy (FLONUM_TYPE *in, FLONUM_TYPE *out)
252b5132 25{
b041f888
KH
26 unsigned int in_length; /* 0 origin */
27 unsigned int out_length; /* 0 origin */
252b5132
RH
28
29 out->sign = in->sign;
30 in_length = in->leader - in->low;
31
32 if (in->leader < in->low)
33 {
34 out->leader = out->low - 1; /* 0.0 case */
35 }
36 else
37 {
38 out_length = out->high - out->low;
b041f888
KH
39 /* Assume no GAPS in packing of littlenums.
40 I.e. sizeof(array) == sizeof(element) * number_of_elements. */
252b5132
RH
41 if (in_length <= out_length)
42 {
43 {
b041f888
KH
44 /* For defensive programming, zero any high-order
45 littlenums we don't need. This is destroying evidence
46 and wasting time, so why bother??? */
252b5132
RH
47 if (in_length < out_length)
48 {
b041f888
KH
49 memset ((char *) (out->low + in_length + 1), '\0',
50 out_length - in_length);
252b5132
RH
51 }
52 }
b041f888
KH
53 memcpy ((void *) (out->low), (void *) (in->low),
54 ((in_length + 1) * sizeof (LITTLENUM_TYPE)));
252b5132
RH
55 out->exponent = in->exponent;
56 out->leader = in->leader - in->low + out->low;
57 }
58 else
59 {
f0e652b4 60 int shorten; /* 1-origin. Number of littlenums we drop. */
252b5132
RH
61
62 shorten = in_length - out_length;
63 /* Assume out_length >= 0 ! */
b041f888
KH
64 memcpy ((void *) (out->low), (void *) (in->low + shorten),
65 ((out_length + 1) * sizeof (LITTLENUM_TYPE)));
252b5132
RH
66 out->leader = out->high;
67 out->exponent = in->exponent + shorten;
68 }
69 } /* if any significant bits */
b041f888 70}