flonum-copy.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* flonum_copy.c - copy a flonum
  2. Copyright (C) 1987 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 1, or (at your option)
  7. any later version.
  8. GAS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GAS; see the file COPYING. If not, write to
  14. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. #include "flonum.h"
  16. #ifdef USG
  17. #define bzero(s,n) memset(s,0,n)
  18. #define bcopy(from,to,n) memcpy(to,from,n)
  19. #endif
  20. void
  21. flonum_copy (in, out)
  22. FLONUM_TYPE * in;
  23. FLONUM_TYPE * out;
  24. {
  25. int in_length; /* 0 origin */
  26. int out_length; /* 0 origin */
  27. out -> sign = in -> sign;
  28. in_length = in -> leader - in -> low;
  29. if (in_length < 0)
  30. {
  31. out -> leader = out -> low - 1; /* 0.0 case */
  32. }
  33. else
  34. {
  35. out_length = out -> high - out -> low;
  36. /*
  37. * Assume no GAPS in packing of littlenums.
  38. * I.e. sizeof(array) == sizeof(element) * number_of_elements.
  39. */
  40. if (in_length <= out_length)
  41. {
  42. {
  43. /*
  44. * For defensive programming, zero any high-order littlenums we don't need.
  45. * This is destroying evidence and wasting time, so why bother???
  46. */
  47. if (in_length < out_length)
  48. {
  49. bzero ((char *)(out->low + in_length + 1), out_length - in_length);
  50. }
  51. }
  52. bcopy ((char *)(in->low), (char *)(out->low), (int)((in_length + 1) * sizeof(LITTLENUM_TYPE)));
  53. out -> exponent = in -> exponent;
  54. out -> leader = in -> leader - in -> low + out -> low;
  55. }
  56. else
  57. {
  58. int shorten; /* 1-origin. Number of littlenums we drop. */
  59. shorten = in_length - out_length;
  60. /* Assume out_length >= 0 ! */
  61. bcopy ((char *)(in->low + shorten),(char *)( out->low), (int)((out_length + 1) * sizeof(LITTLENUM_TYPE)));
  62. out -> leader = out -> high;
  63. out -> exponent = in -> exponent + shorten;
  64. }
  65. } /* if any significant bits */
  66. }
  67. /* end: flonum_copy.c */