summaryrefslogtreecommitdiff
path: root/include/fpfilter.h
blob: 9efa95ee5ea6c2f4f3d89231159a08903232b78e (plain)
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
#ifndef _FPFILTER_H
#define _FPFILTER_H

#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdlib>
#include <iostream>

#define RAT_TO_DBL_ERR 4 * DBL_EPSILON

using namespace std;

int round_nearest();
int round_down();
int round_up();
int round_zero();
//  Set rounding mode.

int
horner_with_err(
  const double* const poly,        //  coefficients of a univariate polynomial
                                   //  in decreasing degree order
  const unsigned long deg,         //  degree of poly
  const double        coeff_err,   //  error bound for coeffs
  const double        in_val,      //  evaluate poly here
  const double        in_err,      //  error bound for in_val
  double&             out_val,     //  value of poly
  double&             out_err      //  bound on absolute error
  );
//  Evaluate poly at in_val. Also, compute a bound on error.

int sign_given_err(const double val, const double err);
//  Returns the sign of val if val might be off from 0.0 by as much as err.
//  Returns 0 if we can't tell.

double newton_for_pseudoroot(const double* const poly,
                             const unsigned long deg,
                             const double coeff_err,
                             const double* const deriv,
                             const double low,
                             const double high);

#endif