ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/zeroes.c
Revision: 2.5
Committed: Thu Jul 17 09:21:29 2003 UTC (20 years, 9 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1, rad5R3, HEAD
Changes since 2.4: +2 -2 lines
Log Message:
Added prototypes and includes from patch by Randolph Fritz.
Added more required includes and reduced other compile warnings.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 2.5 static const char RCSid[] = "$Id: zeroes.c,v 2.4 2003/02/25 02:47:22 greg Exp $";
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 schorsch 2.5 #include "rtmath.h"
17 greg 2.2
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     }