home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Atari / Gnu / gassrc04.zoo / flonum-copy.c < prev    next >
C/C++ Source or Header  |  1991-01-24  |  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 "flonum.h"
  21. #ifdef USG
  22. #define bzero(s,n) memset(s,0,n)
  23. #define bcopy(from,to,n) memcpy(to,from,n)
  24. #endif
  25.  
  26. void
  27. flonum_copy (in, out)
  28.      FLONUM_TYPE *    in;
  29.      FLONUM_TYPE *    out;
  30. {
  31.   int            in_length;    /* 0 origin */
  32.   int            out_length;    /* 0 origin */
  33.  
  34.   out -> sign = in -> sign;
  35.   in_length = in  -> leader - in -> low;
  36.   if (in_length < 0)
  37.     {
  38.       out -> leader = out -> low - 1; /* 0.0 case */
  39.     }
  40.   else
  41.     {
  42.       out_length = out -> high - out -> low;
  43.       /*
  44.        * Assume no GAPS in packing of littlenums.
  45.        * I.e. sizeof(array) == sizeof(element) * number_of_elements.
  46.        */
  47.       if (in_length <= out_length)
  48.     {
  49.       {
  50.         /*
  51.          * For defensive programming, zero any high-order littlenums we don't need.
  52.          * This is destroying evidence and wasting time, so why bother???
  53.          */
  54.         if (in_length < out_length)
  55.           {
  56.         bzero ((char *)(out->low + in_length + 1), out_length - in_length);
  57.           }
  58.       }
  59.       bcopy ((char *)(in->low), (char *)(out->low), (int)((in_length + 1) * sizeof(LITTLENUM_TYPE)));
  60.       out -> exponent = in -> exponent;
  61.       out -> leader   = in -> leader - in -> low + out -> low;
  62.     }
  63.       else
  64.     {
  65.       int    shorten;        /* 1-origin. Number of littlenums we drop. */
  66.  
  67.       shorten = in_length - out_length;
  68.       /* Assume out_length >= 0 ! */
  69.       bcopy ((char *)(in->low + shorten),(char *)( out->low), (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.