The SKIRT project
advanced radiative transfer for astrophysics
Static Public Member Functions | List of all members
Quadratic Class Reference

#include <Quadratic.hpp>

Static Public Member Functions

static void distinctSolutions (double b, double c, double &x1, double &x2)
 
static double smallestPositiveSolution (double b, double c)
 

Detailed Description

This static class offers functions that solve quadratic equations using a numerically stable technique. Specifically, consider a quadratic equation of the form

\[x^2+2bx+c=0.\]

If \(b^2 \ge c\), this equation has solutions described by

\[\begin{aligned} x_1 &= -b - \sqrt{b^2-c} \\ x_2 &= -b + \sqrt{b^2-c} \\ s_1s_2&=c.\end{aligned}\]

To avoid loss of significance in case the solutions have a different order of magnitude, the functions in this class use the first and third equations if \(b>0\) and the second and third equations otherwise.

Member Function Documentation

◆ distinctSolutions()

static void Quadratic::distinctSolutions ( double  b,
double  c,
double &  x1,
double &  x2 
)
inlinestatic

This function determines the solutions of \(x^2 + 2bx + c = 0\). If there are two distinct real solutions, they are stored in the arguments x1 and x2. Otherwise, i.e. if there are no solutions or there is just one real solution, x1 and x2 remain unchanged.

◆ smallestPositiveSolution()

static double Quadratic::smallestPositiveSolution ( double  b,
double  c 
)
inlinestatic

This function returns the smallest positive solution of \(x^2 + 2bx + c = 0\), or zero if there is no positive solution.


The documentation for this class was generated from the following file: