home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / cctools / as / flonum-copy.c < prev    next >
C/C++ Source or Header  |  1993-09-09  |  2KB  |  77 lines

  1. /* flonum_copy.c - copy a flonum
  2.    Copyright (C) 1987 Free Software Foundation, Inc.
  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
  8. the Free Software Foundation; either version 1, or (at your option)
  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
  17. along with GAS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <string.h>
  21. #include "flonum.h"
  22.  
  23. void
  24. flonum_copy(
  25. FLONUM_TYPE *in,
  26. FLONUM_TYPE *out)
  27. {
  28.   int            in_length;    /* 0 origin */
  29.   int            out_length;    /* 0 origin */
  30.  
  31.   out -> sign = in -> sign;
  32.   in_length = in  -> leader - in -> low;
  33.   if (in_length < 0)
  34.     {
  35.       out -> leader = out -> low - 1; /* 0.0 case */
  36.     }
  37.   else
  38.     {
  39.       out_length = out -> high - out -> low;
  40.       /*
  41.        * Assume no GAPS in packing of littlenums.
  42.        * I.e. sizeof(array) == sizeof(element) * number_of_elements.
  43.        */
  44.       if (in_length <= out_length)
  45.     {
  46.       {
  47.         /*
  48.          * For defensive programming, zero any high-order littlenums we don't need.
  49.          * This is destroying evidence and wasting time, so why bother???
  50.          */
  51.         if (in_length < out_length)
  52.           {
  53.         memset((char *)(out->low + in_length + 1), '\0',
  54.                out_length - in_length);
  55.           }
  56.       }
  57.       memcpy((char *)(out->low), (char *)(in->low),
  58.          (int)((in_length + 1) * sizeof(LITTLENUM_TYPE)));
  59.       out -> exponent = in -> exponent;
  60.       out -> leader   = in -> leader - in -> low + out -> low;
  61.     }
  62.       else
  63.     {
  64.       int    shorten;        /* 1-origin. Number of littlenums we drop. */
  65.  
  66.       shorten = in_length - out_length;
  67.       /* Assume out_length >= 0 ! */
  68.       memcpy((char *)(out->low), (char *)(in->low + shorten),
  69.          (int)((out_length + 1) * sizeof(LITTLENUM_TYPE)));
  70.       out -> leader = out -> high;
  71.       out -> exponent = in -> exponent + shorten;
  72.     }
  73.     }                /* if any significant bits */
  74. }
  75.  
  76. /* end: flonum_copy.c */
  77.