Debian Codegraph @

src/c/numbers/one_minus.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 * one_minus.d - implementation of CL:1-
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
16 #include <ecl/ecl.h>
17 #include <ecl/impl/math_dispatch.h>
18
19 /* INV: FLT_MIN - 1 == FLT_MIN
20 * DBL_MIN - 1 == DBL_MIN
21 * LDBL_MIN - 1 == LDBL_MIN
22 * (no ECL_MATHERR_TEST needed) */
23
24 static cl_object
25 ecl_one_minus_fix(cl_object x)
26 {
27 if (x == ecl_make_fixnum(MOST_NEGATIVE_FIXNUM))
28 return ecl_make_integer(MOST_NEGATIVE_FIXNUM-1);
29 return (cl_object)((cl_fixnum)x - ((cl_fixnum)ecl_make_fixnum(1) - ECL_FIXNUM_TAG));
30 }
31
32 static cl_object
33 ecl_one_minus_big(cl_object x)
34 {
35 return ecl_minus(x, ecl_make_fixnum(1));
36 }
37
38 static cl_object
39 ecl_one_minus_ratio(cl_object x)
40 {
41 return ecl_make_ratio(ecl_minus(x->ratio.num,x->ratio.den), x->ratio.den);
42 }
43
44 static cl_object
45 ecl_one_minus_single_float(cl_object x)
46 {
47 return ecl_make_single_float(ecl_single_float(x) - 1);
48 }
49
50 static cl_object
51 ecl_one_minus_double_float(cl_object x)
52 {
53 return ecl_make_double_float(ecl_double_float(x) - 1);
54 }
55
56 static cl_object
57 ecl_one_minus_long_float(cl_object x)
58 {
59 return ecl_make_long_float(ecl_long_float(x) - 1);
60 }
61
62 static cl_object
63 ecl_one_minus_complex(cl_object x)
64 {
65 return ecl_make_complex(ecl_one_minus(x->gencomplex.real),
66 x->gencomplex.imag);
67 }
68
69 #ifdef ECL_COMPLEX_FLOAT
70 static cl_object
71 ecl_one_minus_csfloat(cl_object x)
72 {
73 return ecl_make_csfloat(ecl_csfloat(x) - 1);
74 }
75
76 static cl_object
77 ecl_one_minus_cdfloat(cl_object x)
78 {
79 return ecl_make_cdfloat(ecl_cdfloat(x) - 1);
80 }
81
82 static cl_object
83 ecl_one_minus_clfloat(cl_object x)
84 {
85 return ecl_make_clfloat(ecl_clfloat(x) - 1);
86 }
87 #endif
88
89 MATH_DEF_DISPATCH1_NE(one_minus, @[1-], @[number],
90 ecl_one_minus_fix, ecl_one_minus_big, ecl_one_minus_ratio,
91 ecl_one_minus_single_float, ecl_one_minus_double_float,
92 ecl_one_minus_long_float,
93 ecl_one_minus_complex,
94 ecl_one_minus_csfloat, ecl_one_minus_cdfloat, ecl_one_minus_clfloat);
95
96 /* (1- x) */
97 cl_object
98 @1-(cl_object x)
99 { /* INV: type check is in ecl_one_minus() */
100 @(return ecl_one_minus(x));
101 }