mirror of
https://github.com/vale981/arb
synced 2025-03-05 09:21:38 -05:00
add arb_sgn (sign function)
This commit is contained in:
parent
02cfaa369c
commit
28d78c7c43
4 changed files with 126 additions and 0 deletions
2
arb.h
2
arb.h
|
@ -206,6 +206,8 @@ void arb_neg_round(arb_t x, const arb_t y, slong prec);
|
||||||
|
|
||||||
void arb_abs(arb_t y, const arb_t x);
|
void arb_abs(arb_t y, const arb_t x);
|
||||||
|
|
||||||
|
void arb_sgn(arb_t res, const arb_t x);
|
||||||
|
|
||||||
void _arb_digits_round_inplace(char * s, mp_bitcnt_t * shift, fmpz_t error, slong n, arf_rnd_t rnd);
|
void _arb_digits_round_inplace(char * s, mp_bitcnt_t * shift, fmpz_t error, slong n, arf_rnd_t rnd);
|
||||||
|
|
||||||
int arb_set_str(arb_t res, const char * inp, slong prec);
|
int arb_set_str(arb_t res, const char * inp, slong prec);
|
||||||
|
|
45
arb/sgn.c
Normal file
45
arb/sgn.c
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*=============================================================================
|
||||||
|
|
||||||
|
This file is part of ARB.
|
||||||
|
|
||||||
|
ARB is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
ARB is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with ARB; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
=============================================================================*/
|
||||||
|
/******************************************************************************
|
||||||
|
|
||||||
|
Copyright (C) 2016 Fredrik Johansson
|
||||||
|
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "arb.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
arb_sgn(arb_t res, const arb_t x)
|
||||||
|
{
|
||||||
|
if (arb_is_zero(x))
|
||||||
|
{
|
||||||
|
arb_zero(res);
|
||||||
|
}
|
||||||
|
else if (arb_contains_zero(x))
|
||||||
|
{
|
||||||
|
arf_zero(arb_midref(res));
|
||||||
|
mag_one(arb_radref(res));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arb_set_si(res, arf_sgn(arb_midref(x)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
74
arb/test/t-sgn.c
Normal file
74
arb/test/t-sgn.c
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/*=============================================================================
|
||||||
|
|
||||||
|
This file is part of ARB.
|
||||||
|
|
||||||
|
ARB is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
ARB is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with ARB; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
=============================================================================*/
|
||||||
|
/******************************************************************************
|
||||||
|
|
||||||
|
Copyright (C) 2016 Fredrik Johansson
|
||||||
|
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "arb.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
slong iter;
|
||||||
|
flint_rand_t state;
|
||||||
|
|
||||||
|
flint_printf("sgn....");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
flint_randinit(state);
|
||||||
|
|
||||||
|
for (iter = 0; iter < 1000; iter++)
|
||||||
|
{
|
||||||
|
arb_t a, b;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
arb_init(a);
|
||||||
|
arb_init(b);
|
||||||
|
|
||||||
|
arb_randtest_special(a, state, 1 + n_randint(state, 200), 10);
|
||||||
|
arb_randtest_special(b, state, 1 + n_randint(state, 200), 10);
|
||||||
|
arb_sgn(b, a);
|
||||||
|
|
||||||
|
result = 1;
|
||||||
|
if (arb_contains_zero(a))
|
||||||
|
result = result & arb_contains_si(b, 0);
|
||||||
|
if (arb_contains_positive(a))
|
||||||
|
result = result & arb_contains_si(b, 1);
|
||||||
|
if (arb_contains_negative(a))
|
||||||
|
result = result & arb_contains_si(b, -1);
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
flint_printf("FAIL\n\n");
|
||||||
|
flint_printf("a = "); arb_print(a); flint_printf("\n\n");
|
||||||
|
flint_printf("b = "); arb_print(b); flint_printf("\n\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
arb_clear(a);
|
||||||
|
arb_clear(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
flint_randclear(state);
|
||||||
|
flint_cleanup();
|
||||||
|
flint_printf("PASS\n");
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
|
@ -602,6 +602,11 @@ Arithmetic
|
||||||
Sets *y* to the absolute value of *x*. No attempt is made to improve the
|
Sets *y* to the absolute value of *x*. No attempt is made to improve the
|
||||||
interval represented by *x* if it contains zero.
|
interval represented by *x* if it contains zero.
|
||||||
|
|
||||||
|
.. function:: void arb_sgn(arb_t y, const arb_t x)
|
||||||
|
|
||||||
|
Sets *y* to the sign function of *x*. The result is `[0 \pm 1]` if
|
||||||
|
*x* contains both zero and nonzero numbers.
|
||||||
|
|
||||||
.. function:: void arb_add(arb_t z, const arb_t x, const arb_t y, slong prec)
|
.. function:: void arb_add(arb_t z, const arb_t x, const arb_t y, slong prec)
|
||||||
|
|
||||||
.. function:: void arb_add_arf(arb_t z, const arb_t x, const arf_t y, slong prec)
|
.. function:: void arb_add_arf(arb_t z, const arb_t x, const arf_t y, slong prec)
|
||||||
|
|
Loading…
Add table
Reference in a new issue