spacing_r4.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #define MATHFUNC(funcname) funcname ## f
  22. #if defined (HAVE_GFC_REAL_4) && defined (HAVE_FREXPF)
  23. extern GFC_REAL_4 spacing_r4 (GFC_REAL_4 s, int p, int emin, GFC_REAL_4 tiny);
  24. export_proto(spacing_r4);
  25. GFC_REAL_4
  26. spacing_r4 (GFC_REAL_4 s, int p, int emin, GFC_REAL_4 tiny)
  27. {
  28. int e;
  29. if (s == 0.)
  30. return tiny;
  31. MATHFUNC(frexp) (s, &e);
  32. e = e - p;
  33. e = e > emin ? e : emin;
  34. #if defined (HAVE_LDEXPF)
  35. return MATHFUNC(ldexp) (1., e);
  36. #else
  37. return MATHFUNC(scalbn) (1., e);
  38. #endif
  39. }
  40. #endif