ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/zeroes.c
Revision: 2.4
Committed: Tue Feb 25 02:47:22 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.3: +1 -56 lines
Log Message:
Replaced inline copyright notice with #include "copyright.h"

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.3 static const char RCSid[] = "$Id$";
3 greg 1.1 #endif
4     /*
5     * zeroes.c - compute roots for various equations.
6     *
7 greg 2.3 * External symbols declared in standard.h
8     */
9    
10 greg 2.4 #include "copyright.h"
11 greg 1.1
12    
13 greg 2.2 #include <math.h>
14 greg 1.1
15 greg 2.2 #include "fvect.h"
16    
17    
18 greg 1.1 int
19     quadratic(r, a, b, c) /* find real roots of quadratic equation */
20     double *r; /* roots in ascending order */
21     double a, b, c;
22     {
23     double disc;
24     int first;
25    
26     if (a < -FTINY)
27     first = 1;
28     else if (a > FTINY)
29     first = 0;
30     else if (fabs(b) > FTINY) { /* solve linearly */
31     r[0] = -c/b;
32     return(1);
33     } else
34     return(0); /* equation is c == 0 ! */
35    
36     b *= 0.5; /* simplifies formula */
37    
38     disc = b*b - a*c; /* discriminant */
39    
40     if (disc < -FTINY*FTINY) /* no real roots */
41     return(0);
42    
43     if (disc <= FTINY*FTINY) { /* double root */
44     r[0] = -b/a;
45     return(1);
46     }
47    
48     disc = sqrt(disc);
49    
50     r[first] = (-b - disc)/a;
51     r[1-first] = (-b + disc)/a;
52    
53     return(2);
54     }