Debian Codegraph @

src/c/num_pred.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 * num_pred.d - predicates on numbers
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 #define ECL_INCLUDE_MATH_H
16 #include <ecl/ecl.h>
17 #include <ecl/internal.h>
18 #include <ecl/impl/math_dispatch.h>
19
20 int
21 ecl_oddp(cl_object x)
22 {
23 if (ECL_FIXNUMP(x))
24 return ecl_fixnum(x) & 1;
25 unlikely_if (!ECL_BIGNUMP(x))
26 FEwrong_type_only_arg(@[oddp], x, @[integer]);
27 return _ecl_big_odd_p(x);
28 }
29
30 int
31 ecl_evenp(cl_object x)
32 {
33 if (ECL_FIXNUMP(x))
34 return ~ecl_fixnum(x) & 1;
35 unlikely_if (!ECL_BIGNUMP(x))
36 FEwrong_type_only_arg(@[evenp], x, @[integer]);
37 return _ecl_big_even_p(x);
38 }
39
40 cl_object
41 cl_oddp(cl_object x)
42 { /* INV: ecl_oddp() checks type */
43 @(return (ecl_oddp(x) ? ECL_T : ECL_NIL));
44 }
45
46 cl_object
47 cl_evenp(cl_object x)
48 { /* INV: ecl_evenp() checks_type */
49 @(return (ecl_evenp(x) ? ECL_T : ECL_NIL));
50 }
51
52 cl_object
53 si_float_nan_p(cl_object x)
54 {
55 @(return (ecl_float_nan_p(x)? ECL_T : ECL_NIL));
56 }
57
58 cl_object
59 si_float_infinity_p(cl_object x)
60 {
61 @(return (ecl_float_infinity_p(x)? ECL_T : ECL_NIL));
62 }
63
64 bool
65 ecl_float_nan_p(cl_object x)
66 {
67 switch (ecl_t_of(x)) {
68 case t_singlefloat:
69 return isnan(ecl_single_float(x));
70 case t_doublefloat:
71 return isnan(ecl_double_float(x));
72 case t_longfloat:
73 return isnan(ecl_long_float(x));
74 default:
75 return 0;
76 }
77 }
78
79 bool
80 ecl_float_infinity_p(cl_object x)
81 {
82 switch (ecl_t_of(x)) {
83 case t_singlefloat:
84 return isinf(ecl_single_float(x));
85 case t_doublefloat:
86 return isinf(ecl_double_float(x));
87 case t_longfloat:
88 return isinf(ecl_long_float(x));
89 default:
90 return 0;
91 }
92 }