spacing_r16.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Implementation of the SPACING intrinsic
  2. Copyright (C) 2006-2015 Free Software Foundation, Inc.
  3. Contributed by Steven G. Kargl <kargl@gcc.gnu.org>
  4. This file is part of the GNU Fortran 95 runtime library (libgfortran).
  5. Libgfortran is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either
  8. version 3 of the License, or (at your option) any later version.
  9. Libgfortran is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #include "libgfortran.h"
  21. #if defined(GFC_REAL_16_IS_FLOAT128)
  22. #define MATHFUNC(funcname) funcname ## q
  23. #else
  24. #define MATHFUNC(funcname) funcname ## l
  25. #endif
  26. #if defined (HAVE_GFC_REAL_16) && (defined(GFC_REAL_16_IS_FLOAT128) || defined(HAVE_FREXPL))
  27. extern GFC_REAL_16 spacing_r16 (GFC_REAL_16 s, int p, int emin, GFC_REAL_16 tiny);
  28. export_proto(spacing_r16);
  29. GFC_REAL_16
  30. spacing_r16 (GFC_REAL_16 s, int p, int emin, GFC_REAL_16 tiny)
  31. {
  32. int e;
  33. if (s == 0.)
  34. return tiny;
  35. MATHFUNC(frexp) (s, &e);
  36. e = e - p;
  37. e = e > emin ? e : emin;
  38. #if (defined(GFC_REAL_16_IS_FLOAT128) || defined(HAVE_LDEXPL))
  39. return MATHFUNC(ldexp) (1., e);
  40. #else
  41. return MATHFUNC(scalbn) (1., e);
  42. #endif
  43. }
  44. #endif