flonum-copy.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* flonum_copy.c - copy a flonum
  2. Copyright (C) 1987-2022 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 3, 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 the Free
  14. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. #include "as.h"
  17. void
  18. flonum_copy (FLONUM_TYPE *in, FLONUM_TYPE *out)
  19. {
  20. unsigned int in_length; /* 0 origin */
  21. unsigned int out_length; /* 0 origin */
  22. out->sign = in->sign;
  23. in_length = in->leader - in->low;
  24. if (in->leader < in->low)
  25. {
  26. out->leader = out->low - 1; /* 0.0 case */
  27. }
  28. else
  29. {
  30. out_length = out->high - out->low;
  31. /* Assume no GAPS in packing of littlenums.
  32. I.e. sizeof(array) == sizeof(element) * number_of_elements. */
  33. if (in_length <= out_length)
  34. {
  35. {
  36. /* For defensive programming, zero any high-order
  37. littlenums we don't need. This is destroying evidence
  38. and wasting time, so why bother??? */
  39. if (in_length < out_length)
  40. {
  41. memset ((char *) (out->low + in_length + 1), '\0',
  42. out_length - in_length);
  43. }
  44. }
  45. memcpy ((void *) (out->low), (void *) (in->low),
  46. ((in_length + 1) * sizeof (LITTLENUM_TYPE)));
  47. out->exponent = in->exponent;
  48. out->leader = in->leader - in->low + out->low;
  49. }
  50. else
  51. {
  52. int shorten; /* 1-origin. Number of littlenums we drop. */
  53. shorten = in_length - out_length;
  54. /* Assume out_length >= 0 ! */
  55. memcpy ((void *) (out->low), (void *) (in->low + shorten),
  56. ((out_length + 1) * sizeof (LITTLENUM_TYPE)));
  57. out->leader = out->high;
  58. out->exponent = in->exponent + shorten;
  59. }
  60. } /* if any significant bits */
  61. }