INNER CODE UNIT · TypeScript
solveCubic
margelo/react-native-graph · src/GetYForX.ts:21
const solveCubic = (a: number, b: number, c: number, d: number): number[] => {
'worklet';
if (Math.abs(a) < 1e-8) {
// Quadratic case, ax^2+bx+c=0
a = b;
b = c;
c = d;
if (Math.abs(a) < 1e-8) {
// Linear case, ax+b=0
a = b;
b = c;
if (Math.abs(a) < 1e-8) {
// Degenerate case
return [];
}
return [-b / a];
}