Back to index

radiance  4R0+20100331
Functions | Variables
zeroes.c File Reference
#include "copyright.h"
#include <math.h>
#include "fvect.h"
#include "rtmath.h"

Go to the source code of this file.

Functions

int quadratic (double *r, double a, double b, double c)

Variables

static const char RCSid [] = "$Id: zeroes.c,v 2.5 2003/07/17 09:21:29 schorsch Exp $"

Function Documentation

int quadratic ( double *  r,
double  a,
double  b,
double  c 
)

Definition at line 19 of file zeroes.c.

{
       double  disc;
       int  first;

       if (a < -FTINY)
              first = 1;
       else if (a > FTINY)
              first = 0;
       else if (fabs(b) > FTINY) { /* solve linearly */
              r[0] = -c/b;
              return(1);
       } else
              return(0);           /* equation is c == 0 ! */
              
       b *= 0.5;                   /* simplifies formula */
       
       disc = b*b - a*c;           /* discriminant */

       if (disc < -FTINY*FTINY)    /* no real roots */
              return(0);

       if (disc <= FTINY*FTINY) {  /* double root */
              r[0] = -b/a;
              return(1);
       }
       
       disc = sqrt(disc);

       r[first] = (-b - disc)/a;
       r[1-first] = (-b + disc)/a;

       return(2);
}

Here is the caller graph for this function:


Variable Documentation

const char RCSid[] = "$Id: zeroes.c,v 2.5 2003/07/17 09:21:29 schorsch Exp $" [static]

Definition at line 2 of file zeroes.c.