1 1.1 mrg `/* Implementation of the MAXVAL intrinsic 2 1.1.1.3 mrg Copyright (C) 2002-2022 Free Software Foundation, Inc. 3 1.1 mrg Contributed by Paul Brook <paul (a] nowt.org> 4 1.1 mrg 5 1.1 mrg This file is part of the GNU Fortran runtime library (libgfortran). 6 1.1 mrg 7 1.1 mrg Libgfortran is free software; you can redistribute it and/or 8 1.1 mrg modify it under the terms of the GNU General Public 9 1.1 mrg License as published by the Free Software Foundation; either 10 1.1 mrg version 3 of the License, or (at your option) any later version. 11 1.1 mrg 12 1.1 mrg Libgfortran is distributed in the hope that it will be useful, 13 1.1 mrg but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 mrg GNU General Public License for more details. 16 1.1 mrg 17 1.1 mrg Under Section 7 of GPL version 3, you are granted additional 18 1.1 mrg permissions described in the GCC Runtime Library Exception, version 19 1.1 mrg 3.1, as published by the Free Software Foundation. 20 1.1 mrg 21 1.1 mrg You should have received a copy of the GNU General Public License and 22 1.1 mrg a copy of the GCC Runtime Library Exception along with this program; 23 1.1 mrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24 1.1 mrg <http://www.gnu.org/licenses/>. */ 25 1.1 mrg 26 1.1 mrg #include "libgfortran.h"' 27 1.1 mrg 28 1.1 mrg include(iparm.m4)dnl 29 1.1 mrg include(ifunction.m4)dnl 30 1.1 mrg 31 1.1 mrg `#if defined (HAVE_'atype_name`) && defined (HAVE_'rtype_name`)' 32 1.1 mrg 33 1.1 mrg ARRAY_FUNCTION(atype_min, 34 1.1 mrg `#if defined ('atype_inf`) 35 1.1 mrg result = -atype_inf; 36 1.1 mrg #else 37 1.1 mrg result = atype_min; 38 1.1 mrg #endif', 39 1.1 mrg `#if defined ('atype_nan`) 40 1.1 mrg if (*src >= result) 41 1.1 mrg break; 42 1.1 mrg } 43 1.1 mrg if (unlikely (n >= len)) 44 1.1 mrg result = atype_nan; 45 1.1 mrg else for (; n < len; n++, src += delta) 46 1.1 mrg { 47 1.1 mrg #endif 48 1.1 mrg if (*src > result) 49 1.1 mrg result = *src;', `') 50 1.1 mrg 51 1.1 mrg MASKED_ARRAY_FUNCTION(atype_min, 52 1.1 mrg `#if defined ('atype_inf`) 53 1.1 mrg result = -atype_inf; 54 1.1 mrg #else 55 1.1 mrg result = atype_min; 56 1.1 mrg #endif 57 1.1 mrg #if defined ('atype_nan`) 58 1.1 mrg int non_empty_p = 0; 59 1.1 mrg #endif', 60 1.1 mrg `#if defined ('atype_inf`) || defined ('atype_nan`) 61 1.1 mrg if (*msrc) 62 1.1 mrg { 63 1.1 mrg #if defined ('atype_nan`) 64 1.1 mrg non_empty_p = 1; 65 1.1 mrg if (*src >= result) 66 1.1 mrg #endif 67 1.1 mrg break; 68 1.1 mrg } 69 1.1 mrg } 70 1.1 mrg if (unlikely (n >= len)) 71 1.1 mrg { 72 1.1 mrg #if defined ('atype_nan`) 73 1.1 mrg result = non_empty_p ? atype_nan : atype_min; 74 1.1 mrg #else 75 1.1 mrg result = atype_min; 76 1.1 mrg #endif 77 1.1 mrg } 78 1.1 mrg else for (; n < len; n++, src += delta, msrc += mdelta) 79 1.1 mrg { 80 1.1 mrg #endif 81 1.1 mrg if (*msrc && *src > result) 82 1.1 mrg result = *src;') 83 1.1 mrg 84 1.1 mrg SCALAR_ARRAY_FUNCTION(atype_min) 85 1.1 mrg 86 1.1 mrg #endif 87