~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to imagery/i.smap/bouman/solve.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
double solve(
3
 
                /* Solves equation (*f)(x) = 0 on x in [a,b]. Uses half interval method. */
4
 
                /* Requires that (*f)(a) and (*f)(b) have opposite signs.               */
5
 
                /* Returns code=0 if signs are opposite.                                */
6
 
                /* Returns code=1 if signs are both positive.                           */
7
 
                /* Returns code=1 if signs are both negative.                           */
8
 
                double (*f) (double),   /* pointer to function to be solved */
9
 
                double a,       /* minimum value of solution */
10
 
                double b,       /* maximum value of solution */
11
 
                double err,     /* accuarcy of solution */
12
 
                int *code       /* error code */
13
 
    )
14
 
{
15
 
    int signa, signb, signc;
16
 
    double fa, fb, fc, c, signaling_nan();
17
 
    double dist;
18
 
 
19
 
    fa = (*f) (a);
20
 
    signa = fa > 0;
21
 
    fb = (*f) (b);
22
 
    signb = fb > 0;
23
 
 
24
 
    /* check starting conditions */
25
 
    if (signa == signb) {
26
 
        if (signa == 1)
27
 
            *code = 1;
28
 
        else
29
 
            *code = -1;
30
 
        return (0.0);
31
 
    }
32
 
    else
33
 
        *code = 0;
34
 
 
35
 
    /* half interval search */
36
 
    if ((dist = b - a) < 0)
37
 
        dist = -dist;
38
 
    while (dist > err) {
39
 
        c = (b + a) / 2;
40
 
        fc = (*f) (c);
41
 
        signc = fc > 0;
42
 
        if (signa == signc) {
43
 
            a = c;
44
 
            fa = fc;
45
 
        }
46
 
        else {
47
 
            b = c;
48
 
            fb = fc;
49
 
        }
50
 
        if ((dist = b - a) < 0)
51
 
            dist = -dist;
52
 
    }
53
 
 
54
 
    /* linear interpolation */
55
 
    if ((fb - fa) == 0)
56
 
        return (a);
57
 
    else {
58
 
        c = (a * fb - b * fa) / (fb - fa);
59
 
        return (c);
60
 
    }
61
 
}