mirror of
https://github.com/vale981/arb
synced 2025-03-04 08:51:40 -05:00
add arb_sgn_nonzero
This commit is contained in:
parent
c4dfa614b4
commit
81c481b526
5 changed files with 36 additions and 30 deletions
1
arb.h
1
arb.h
|
@ -159,6 +159,7 @@ 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_sgn(arb_t res, const arb_t x);
|
||||
int arb_sgn_nonzero(const arb_t x);
|
||||
|
||||
void _arb_digits_round_inplace(char * s, mp_bitcnt_t * shift, fmpz_t error, slong n, arf_rnd_t rnd);
|
||||
|
||||
|
|
23
arb/sgn_nonzero.c
Normal file
23
arb/sgn_nonzero.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
Copyright (C) 2019 Fredrik Johansson
|
||||
|
||||
This file is part of Arb.
|
||||
|
||||
Arb 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 "arb.h"
|
||||
|
||||
int
|
||||
arb_sgn_nonzero(const arb_t x)
|
||||
{
|
||||
if (arb_is_positive(x))
|
||||
return 1;
|
||||
else if (arb_is_negative(x))
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
|
@ -15,18 +15,6 @@
|
|||
#define BLOCK_ISOLATED_ZERO 1
|
||||
#define BLOCK_UNKNOWN 2
|
||||
|
||||
/* 0 means that it *could* be zero; otherwise +/- 1 */
|
||||
static __inline__ int
|
||||
_arb_sign(const arb_t t)
|
||||
{
|
||||
if (arb_is_positive(t))
|
||||
return 1;
|
||||
else if (arb_is_negative(t))
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
check_block(arb_calc_func_t func, void * param, const arf_interval_t block,
|
||||
int asign, int bsign, slong prec)
|
||||
|
@ -175,11 +163,11 @@ arb_calc_isolate_roots(arf_interval_ptr * blocks, int ** flags,
|
|||
|
||||
arb_set_arf(m, &block->a);
|
||||
func(v, m, param, 1, prec);
|
||||
asign = _arb_sign(v);
|
||||
asign = arb_sgn_nonzero(v);
|
||||
|
||||
arb_set_arf(m, &block->b);
|
||||
func(v, m, param, 1, prec);
|
||||
bsign = _arb_sign(v);
|
||||
bsign = arb_sgn_nonzero(v);
|
||||
|
||||
arb_clear(m);
|
||||
arb_clear(v);
|
||||
|
|
|
@ -13,18 +13,6 @@
|
|||
|
||||
/* TODO: refactor/combine some of this code with isolate_roots.c */
|
||||
|
||||
/* 0 means that it *could* be zero; otherwise +/- 1 */
|
||||
static __inline__ int
|
||||
_arb_sign(const arb_t t)
|
||||
{
|
||||
if (arb_is_positive(t))
|
||||
return 1;
|
||||
else if (arb_is_negative(t))
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int arb_calc_partition(arf_interval_t L, arf_interval_t R,
|
||||
arb_calc_func_t func, void * param, const arf_interval_t block, slong prec)
|
||||
{
|
||||
|
@ -43,7 +31,7 @@ int arb_calc_partition(arf_interval_t L, arf_interval_t R,
|
|||
/* Evaluate and get sign at midpoint */
|
||||
arb_set_arf(m, u);
|
||||
func(t, m, param, 1, prec);
|
||||
msign = _arb_sign(t);
|
||||
msign = arb_sgn_nonzero(t);
|
||||
|
||||
/* L, R = block, split at midpoint */
|
||||
arf_set(&L->a, &block->a);
|
||||
|
@ -73,11 +61,11 @@ int arb_calc_refine_root_bisect(arf_interval_t r, arb_calc_func_t func,
|
|||
|
||||
arb_set_arf(m, &start->a);
|
||||
func(v, m, param, 1, prec);
|
||||
asign = _arb_sign(v);
|
||||
asign = arb_sgn_nonzero(v);
|
||||
|
||||
arb_set_arf(m, &start->b);
|
||||
func(v, m, param, 1, prec);
|
||||
bsign = _arb_sign(v);
|
||||
bsign = arb_sgn_nonzero(v);
|
||||
|
||||
/* must have proper sign changes */
|
||||
if (asign == 0 || bsign == 0 || asign == bsign)
|
||||
|
|
|
@ -599,7 +599,7 @@ Comparisons
|
|||
Returns nonzero iff the given number (or ball) *y* is contained in
|
||||
the interval represented by *x*.
|
||||
|
||||
If *x* is contains NaN, this function always returns nonzero (as it
|
||||
If *x* contains NaN, this function always returns nonzero (as it
|
||||
could represent anything, and in particular could represent all
|
||||
the points included in *y*).
|
||||
If *y* contains NaN and *x* does not, it always returns zero.
|
||||
|
@ -666,6 +666,12 @@ Arithmetic
|
|||
Sets *y* to the sign function of *x*. The result is `[0 \pm 1]` if
|
||||
*x* contains both zero and nonzero numbers.
|
||||
|
||||
.. function:: int arb_sgn_nonzero(const arb_t x)
|
||||
|
||||
Returns 1 if *x* is strictly positive, -1 if *x* is strictly negative,
|
||||
and 0 if *x* is zero or a ball containing zero so that its sign
|
||||
is not determined.
|
||||
|
||||
.. function:: void arb_min(arb_t z, const arb_t x, const arb_t y, slong prec)
|
||||
|
||||
.. function:: void arb_max(arb_t z, const arb_t x, const arb_t y, slong prec)
|
||||
|
|
Loading…
Add table
Reference in a new issue