add arb_sgn_nonzero

This commit is contained in:
fredrik 2019-02-12 09:22:08 +01:00
parent c4dfa614b4
commit 81c481b526
5 changed files with 36 additions and 30 deletions

1
arb.h
View file

@ -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_abs(arb_t y, const arb_t x);
void arb_sgn(arb_t res, 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); 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
View 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;
}

View file

@ -15,18 +15,6 @@
#define BLOCK_ISOLATED_ZERO 1 #define BLOCK_ISOLATED_ZERO 1
#define BLOCK_UNKNOWN 2 #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 static int
check_block(arb_calc_func_t func, void * param, const arf_interval_t block, check_block(arb_calc_func_t func, void * param, const arf_interval_t block,
int asign, int bsign, slong prec) 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); arb_set_arf(m, &block->a);
func(v, m, param, 1, prec); func(v, m, param, 1, prec);
asign = _arb_sign(v); asign = arb_sgn_nonzero(v);
arb_set_arf(m, &block->b); arb_set_arf(m, &block->b);
func(v, m, param, 1, prec); func(v, m, param, 1, prec);
bsign = _arb_sign(v); bsign = arb_sgn_nonzero(v);
arb_clear(m); arb_clear(m);
arb_clear(v); arb_clear(v);

View file

@ -13,18 +13,6 @@
/* TODO: refactor/combine some of this code with isolate_roots.c */ /* 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, 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) 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 */ /* Evaluate and get sign at midpoint */
arb_set_arf(m, u); arb_set_arf(m, u);
func(t, m, param, 1, prec); func(t, m, param, 1, prec);
msign = _arb_sign(t); msign = arb_sgn_nonzero(t);
/* L, R = block, split at midpoint */ /* L, R = block, split at midpoint */
arf_set(&L->a, &block->a); 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); arb_set_arf(m, &start->a);
func(v, m, param, 1, prec); func(v, m, param, 1, prec);
asign = _arb_sign(v); asign = arb_sgn_nonzero(v);
arb_set_arf(m, &start->b); arb_set_arf(m, &start->b);
func(v, m, param, 1, prec); func(v, m, param, 1, prec);
bsign = _arb_sign(v); bsign = arb_sgn_nonzero(v);
/* must have proper sign changes */ /* must have proper sign changes */
if (asign == 0 || bsign == 0 || asign == bsign) if (asign == 0 || bsign == 0 || asign == bsign)

View file

@ -599,7 +599,7 @@ Comparisons
Returns nonzero iff the given number (or ball) *y* is contained in Returns nonzero iff the given number (or ball) *y* is contained in
the interval represented by *x*. 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 could represent anything, and in particular could represent all
the points included in *y*). the points included in *y*).
If *y* contains NaN and *x* does not, it always returns zero. 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 Sets *y* to the sign function of *x*. The result is `[0 \pm 1]` if
*x* contains both zero and nonzero numbers. *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_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) .. function:: void arb_max(arb_t z, const arb_t x, const arb_t y, slong prec)