1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
/*
Copyright (C) 2021 Fredrik Johansson
This file is part of Calcium.
Calcium is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
#include "ca.h"
/* todo: better impl */
/* may want to return symbolic csgn (can still bound numerically) */
void
ca_csgn(ca_t res, const ca_t x, ca_ctx_t ctx)
{
ca_t re, im, zero;
truth_t is_zero;
if (CA_IS_SPECIAL(x))
{
if (ca_check_is_signed_inf(x, ctx) == T_TRUE)
{
ca_sgn(res, x, ctx);
ca_csgn(res, res, ctx);
}
else if (ca_check_is_uinf(x, ctx) == T_TRUE || ca_check_is_undefined(x, ctx) == T_TRUE)
{
ca_undefined(res, ctx);
}
else
{
ca_unknown(res, ctx);
}
return;
}
is_zero = ca_check_is_zero(x, ctx);
if (is_zero == T_TRUE)
{
ca_zero(res, ctx);
return;
}
if (is_zero == T_UNKNOWN)
{
ca_unknown(res, ctx);
return;
}
ca_init(re, ctx);
ca_init(zero, ctx);
ca_re(re, x, ctx);
if (ca_check_gt(re, zero, ctx) == T_TRUE)
{
ca_one(res, ctx);
}
else if (ca_check_lt(re, zero, ctx) == T_TRUE)
{
ca_neg_one(res, ctx);
}
else if (ca_check_is_zero(re, ctx) == T_TRUE)
{
ca_init(im, ctx);
ca_im(im, x, ctx);
if (ca_check_gt(im, zero, ctx) == T_TRUE)
{
ca_one(res, ctx);
}
else if (ca_check_lt(im, zero, ctx) == T_TRUE)
{
ca_neg_one(res, ctx);
}
else
{
ca_unknown(res, ctx);
}
ca_clear(im, ctx);
}
else
{
ca_unknown(res, ctx);
}
ca_clear(re, ctx);
}
|