Implementation
factory LinearRegression(Registers regs) {
regs[7]; // Throw exception if invalid
final num = regs[2].asDouble;
if (num == 0 || num == 1) {
throw CalculatorError(0);
}
final sumX = regs[3].asDouble;
final m = num * regs[4].asDouble - sumX * sumX;
final sumY = regs[5].asDouble;
final n = num * regs[6].asDouble - sumY * sumY;
if (m == 0 || n == 0) {
throw CalculatorError(0);
}
final p = num * regs[7].asDouble - sumX * sumY;
return LinearRegression._internal(num, m, n, p, sumY, sumX);
}