How to convert from float to double?

I have a library with an array:

float xyz[3];

In the ino file I have to send on them to the PID as input.

double a;
PID myPID(&xin, &a, &b, 1, 0.0, 1.1, DIRECT);
...
void loop(){
  xin = mylib.ypr[2];   
  myPID.Compute();
Serial.print(a); //output: "nan"
...
}

looking into the PID.h I see

PID::PID(double* Input, double* Output, double* Setpoint,
        double Kp, double Ki, double Kd, int ControllerDirection)

It compiles but the output of the PID outvalue is nan.

How can I fix this?

Hi,
I'm not quite sure but I want to give you a hint what it could be.

For the fourth paramter of the constructor a double is expected, but you are passing in an int. It could be that the compiler accepts that, but does not convert the int properly to a double. To do so, you can change 1 to 1.0 or even better 1.0d, wheras the d tells the compiler that the value should be handeled as double. But it's just a suggestion. Let me hear if that is changing something!

Greetings

Unless you're using a Due, a float is the same as a double.

Post your code.

I am using Mega 2560.

xin = mylib.ypr[2];   
xin = -10.0; //Works
  myPID.Compute();
Serial.print(a); //output: "1120"

The int didnt matter. I think the compiler converts the int to double anyway.
When I set the xin to -10 then it works correctly.
So there is a problem with the float array.
I have tried: xin = double(mylib.ypr[2]); with no luck.

Kai_Heinz:
Hi,
I'm not quite sure but I want to give you a hint what it could be.

For the fourth paramter of the constructor a double is expected, but you are passing in an int. It could be that the compiler accepts that, but does not convert the int properly to a double. To do so, you can change 1 to 1.0 or even better 1.0d, wheras the d tells the compiler that the value should be handeled as double. But it's just a suggestion. Let me hear if that is changing something!

Greetings