| 1 |
/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
| 2 |
/* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */ |
| 3 |
|
| 4 |
/* |
| 5 |
* negate.d - trascendental functions: negateine |
| 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 |
#include <ecl/impl/math_dispatch.h> |
| 17 |
|
| 18 |
static cl_object |
| 19 |
ecl_negate_fix(cl_object x) |
| 20 |
{ |
| 21 |
return ecl_make_integer(-ecl_fixnum(x)); |
| 22 |
} |
| 23 |
|
| 24 |
static cl_object |
| 25 |
ecl_negate_big(cl_object x) |
| 26 |
{ |
| 27 |
return _ecl_big_negate(x); |
| 28 |
} |
| 29 |
|
| 30 |
static cl_object |
| 31 |
ecl_negate_ratio(cl_object x) |
| 32 |
{ |
| 33 |
return ecl_make_ratio(ecl_negate(x->ratio.num), x->ratio.den); |
| 34 |
} |
| 35 |
|
| 36 |
static cl_object |
| 37 |
ecl_negate_single_float(cl_object x) |
| 38 |
{ |
| 39 |
return ecl_make_single_float(-ecl_single_float(x)); |
| 40 |
} |
| 41 |
|
| 42 |
static cl_object |
| 43 |
ecl_negate_double_float(cl_object x) |
| 44 |
{ |
| 45 |
return ecl_make_double_float(-ecl_double_float(x)); |
| 46 |
} |
| 47 |
|
| 48 |
static cl_object |
| 49 |
ecl_negate_long_float(cl_object x) |
| 50 |
{ |
| 51 |
return ecl_make_long_float(-ecl_long_float(x)); |
| 52 |
} |
| 53 |
|
| 54 |
static cl_object |
| 55 |
ecl_negate_complex(cl_object x) |
| 56 |
{ |
| 57 |
return ecl_make_complex(ecl_negate(x->gencomplex.real), |
| 58 |
ecl_negate(x->gencomplex.imag)); |
| 59 |
} |
| 60 |
|
| 61 |
#ifdef ECL_COMPLEX_FLOAT |
| 62 |
static cl_object |
| 63 |
ecl_negate_csfloat(cl_object x) |
| 64 |
{ |
| 65 |
return ecl_make_csfloat(-ecl_csfloat(x)); |
| 66 |
} |
| 67 |
|
| 68 |
static cl_object |
| 69 |
ecl_negate_cdfloat(cl_object x) |
| 70 |
{ |
| 71 |
return ecl_make_cdfloat(-ecl_cdfloat(x)); |
| 72 |
} |
| 73 |
|
| 74 |
static cl_object |
| 75 |
ecl_negate_clfloat(cl_object x) |
| 76 |
{ |
| 77 |
return ecl_make_clfloat(-ecl_clfloat(x)); |
| 78 |
} |
| 79 |
#endif |
| 80 |
|
| 81 |
MATH_DEF_DISPATCH1_NE(negate, @[-], @[number], |
| 82 |
ecl_negate_fix, ecl_negate_big, ecl_negate_ratio, |
| 83 |
ecl_negate_single_float, ecl_negate_double_float, |
| 84 |
ecl_negate_long_float, |
| 85 |
ecl_negate_complex, |
| 86 |
ecl_negate_csfloat, ecl_negate_cdfloat, ecl_negate_clfloat); |