Debian Codegraph @

src/c/numbers/minmax.d

raw
1 /* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */
3
4 /*
5 * minmax.c - number sorting
6 *
7 * Copyright (c) 1984 Taiichi Yuasa and Masami Hagiya
8 * Copyright (c) 1990 Giuseppe Attardi
9 * Copyright (c) 2001 Juan Jose Garcia Ripoll
10 *
11 * See file 'LICENSE' for the copyright details.
12 *
13 */
14
15 #include <ecl/ecl.h>
16
17 @(defun max (max &rest nums)
18 @
19 /* INV: type check occurs in ecl_number_compare() for the rest of
20 numbers, but for an unary argument it happens here. */
21 if (narg-- == 1) {
22 if (! ECL_REAL_TYPE_P(ecl_t_of(max))) {
23 FEwrong_type_nth_arg(@[max], 1, max, @[real]);
24 }
25 } else do {
26 cl_object numi = ecl_va_arg(nums);
27 if (ecl_lower(max, numi)
28 #ifdef ECL_IEEE_FP
29 || ecl_float_nan_p(max)
30 #endif
31 )
32 max = numi;
33 } while (--narg);
34 @(return max);
35 @)
36
37 @(defun min (min &rest nums)
38 @
39 /* INV: type check occurs in ecl_number_compare() for the rest of
40 numbers, but for an unary argument it happens here. */
41 if (narg-- == 1) {
42 if (! ECL_REAL_TYPE_P(ecl_t_of(min))) {
43 FEwrong_type_nth_arg(@[min], 1, min, @[real]);
44 }
45 } else do {
46 cl_object numi = ecl_va_arg(nums);
47 if (ecl_greater(min, numi)
48 #ifdef ECL_IEEE_FP
49 || ecl_float_nan_p(min)
50 #endif
51 )
52 min = numi;
53 } while (--narg);
54 @(return min);
55 @)