Running the code shown below on a Teensy 36 gives big integers as result where negative values should occur. Output of the code is shown below also. If the line with "..random.." is replaced by one of the lines given below this error does not occur. If the code is run on an Arduino Uno the error also does not occur. Any idea what happens? Could one of you test if the error occurs also at his site?
Code:
void setup() {
Serial.begin(9600);
delay(2000) ;
Serial.print("Hello World 1\n");
randomSeed(1);
for(int k=0 ; k<20 ; k++){
double x=random(10)-5 ;
Serial.printf("%5d %15.5f \n",k,x) ;
}
}
// these lines work:
//double x=random(10)-5.0f ;
//double x=(int)random(10)-5 ;
//int i=random(10)-5 ; double x=(double)i ;
//long i=random(10)-5 ; double x=(double)i ;
//double x=(long)random(10)-5 ;
void loop(){
}
Program output is
Hello World 1
0 2.00000
1 4.00000
2 4294967294.00000
3 3.00000
4 4294967291.00000
5 4294967293.00000
6 4294967295.00000
7 3.00000
8 4294967294.00000