maxval.m4 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. `/* Implementation of the MAXVAL intrinsic
  2. Copyright (C) 2002-2015 Free Software Foundation, Inc.
  3. Contributed by Paul Brook <paul@nowt.org>
  4. This file is part of the GNU Fortran 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. #include <stdlib.h>
  22. #include <assert.h>'
  23. include(iparm.m4)dnl
  24. include(ifunction.m4)dnl
  25. `#if defined (HAVE_'atype_name`) && defined (HAVE_'rtype_name`)'
  26. ARRAY_FUNCTION(atype_min,
  27. `#if defined ('atype_inf`)
  28. result = -atype_inf;
  29. #else
  30. result = atype_min;
  31. #endif',
  32. `#if defined ('atype_nan`)
  33. if (*src >= result)
  34. break;
  35. }
  36. if (unlikely (n >= len))
  37. result = atype_nan;
  38. else for (; n < len; n++, src += delta)
  39. {
  40. #endif
  41. if (*src > result)
  42. result = *src;', `')
  43. MASKED_ARRAY_FUNCTION(atype_min,
  44. `#if defined ('atype_inf`)
  45. result = -atype_inf;
  46. #else
  47. result = atype_min;
  48. #endif
  49. #if defined ('atype_nan`)
  50. int non_empty_p = 0;
  51. #endif',
  52. `#if defined ('atype_inf`) || defined ('atype_nan`)
  53. if (*msrc)
  54. {
  55. #if defined ('atype_nan`)
  56. non_empty_p = 1;
  57. if (*src >= result)
  58. #endif
  59. break;
  60. }
  61. }
  62. if (unlikely (n >= len))
  63. {
  64. #if defined ('atype_nan`)
  65. result = non_empty_p ? atype_nan : atype_min;
  66. #else
  67. result = atype_min;
  68. #endif
  69. }
  70. else for (; n < len; n++, src += delta, msrc += mdelta)
  71. {
  72. #endif
  73. if (*msrc && *src > result)
  74. result = *src;')
  75. SCALAR_ARRAY_FUNCTION(atype_min)
  76. #endif