I've tried to compile the program below with the latest (1.6.6.) and
with the 1.5.7 environment, but both give an error (see below) when
i 'un-comment' the first Serial.println statement in the SimpleLinearRegression
function.
google searches indicated that this could be due to:
- non printable characters in the code (not the case here)
- compiler bug (could be? but then i've tried two different ones and both still give the issue)
- 'old' arduino software that was installed on the same pc and is messing things up (but i've deleted all previous arduino installations and related stuff)
what am i missing?
void SimpleLinearRegression(double *arr, int n, double slope){
double x = (float(n)-1.0f) * float(n) / 2;
double xx = 0.0f;
double y = 0.0f;
double xy = 0.0f;
for ( int i = 0; i < n; i++) {
xx += i * i;
y += arr[i];
xy += i * arr[i];
}
Serial.println(xx); // when commenting this line, the sketch compiles
Serial.println(y);
Serial.println(xy);
Serial.println(x);
slope = (float(n) * xy - x * y) / (float(n) * xx - x * x);
}
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
double g[4] = {0,2,4,6};
int n = 4;
double slope = 0.0f;
Serial.println(slope);
SimpleLinearRegression(g,n,slope);
Serial.println(slope);
}
For reference: the error
sketch_nov27a.ino: In function 'void SimpleLinearRegression(double*, int, double)':
sketch_nov27a.ino:22:1: error: unable to find a register to spill in class 'POINTER_REGS'
sketch_nov27a.ino:22:1: error: this is the insn:
(insn 68 67 70 3 (set (reg:SF 71 [ D.3834 ])
(mem:SF (post_inc:HI (reg:HI 2 r2 [orig:74 ivtmp.12 ] [74])) [2 MEM[base: _34, offset: 0B]+0 S4 A8])) sketch_nov27a.ino:11 99 {*movsf}
(expr_list:REG_INC (reg:HI 2 r2 [orig:74 ivtmp.12 ] [74])
(nil)))
sketch_nov27a.ino:22: confused by earlier errors, bailing out