133965Sjdp/* flonum_copy.c - copy a flonum
2218822Sdim   Copyright 1987, 1990, 1991, 1992, 1993, 2000, 2003
378828Sobrien   Free Software Foundation, Inc.
433965Sjdp
533965Sjdp   This file is part of GAS, the GNU Assembler.
633965Sjdp
733965Sjdp   GAS is free software; you can redistribute it and/or modify
833965Sjdp   it under the terms of the GNU General Public License as published by
933965Sjdp   the Free Software Foundation; either version 2, or (at your option)
1033965Sjdp   any later version.
1133965Sjdp
1233965Sjdp   GAS is distributed in the hope that it will be useful,
1333965Sjdp   but WITHOUT ANY WARRANTY; without even the implied warranty of
1433965Sjdp   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1533965Sjdp   GNU General Public License for more details.
1633965Sjdp
1733965Sjdp   You should have received a copy of the GNU General Public License
1877298Sobrien   along with GAS; see the file COPYING.  If not, write to the Free
19218822Sdim   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20218822Sdim   02110-1301, USA.  */
2133965Sjdp
2233965Sjdp#include "as.h"
2333965Sjdp
2433965Sjdpvoid
25130561Sobrienflonum_copy (FLONUM_TYPE *in, FLONUM_TYPE *out)
2633965Sjdp{
2777298Sobrien  unsigned int in_length;	/* 0 origin */
2877298Sobrien  unsigned int out_length;	/* 0 origin */
2933965Sjdp
3033965Sjdp  out->sign = in->sign;
3133965Sjdp  in_length = in->leader - in->low;
3233965Sjdp
3333965Sjdp  if (in->leader < in->low)
3433965Sjdp    {
3533965Sjdp      out->leader = out->low - 1;	/* 0.0 case */
3633965Sjdp    }
3733965Sjdp  else
3833965Sjdp    {
3933965Sjdp      out_length = out->high - out->low;
4077298Sobrien      /* Assume no GAPS in packing of littlenums.
4177298Sobrien	 I.e. sizeof(array) == sizeof(element) * number_of_elements.  */
4233965Sjdp      if (in_length <= out_length)
4333965Sjdp	{
4433965Sjdp	  {
4577298Sobrien	    /* For defensive programming, zero any high-order
4677298Sobrien	       littlenums we don't need.  This is destroying evidence
4777298Sobrien	       and wasting time, so why bother???  */
4833965Sjdp	    if (in_length < out_length)
4933965Sjdp	      {
5077298Sobrien		memset ((char *) (out->low + in_length + 1), '\0',
5177298Sobrien			out_length - in_length);
5233965Sjdp	      }
5333965Sjdp	  }
5477298Sobrien	  memcpy ((void *) (out->low), (void *) (in->low),
5577298Sobrien		  ((in_length + 1) * sizeof (LITTLENUM_TYPE)));
5633965Sjdp	  out->exponent = in->exponent;
5733965Sjdp	  out->leader = in->leader - in->low + out->low;
5833965Sjdp	}
5933965Sjdp      else
6033965Sjdp	{
6177298Sobrien	  int shorten;		/* 1-origin. Number of littlenums we drop.  */
6233965Sjdp
6333965Sjdp	  shorten = in_length - out_length;
6433965Sjdp	  /* Assume out_length >= 0 ! */
6577298Sobrien	  memcpy ((void *) (out->low), (void *) (in->low + shorten),
6677298Sobrien		  ((out_length + 1) * sizeof (LITTLENUM_TYPE)));
6733965Sjdp	  out->leader = out->high;
6833965Sjdp	  out->exponent = in->exponent + shorten;
6933965Sjdp	}
7033965Sjdp    }				/* if any significant bits */
7177298Sobrien}
72