Problem with asin();

400*400 = 160000, which overflows a short. Also, the input to asin() must be in the range {-1, 1}.

The following code produces this output:

z-height: 0.00
vector length: 250.00
half beta in sine: 0.83
beta: 112.89

float square(float x) {
  return x * x;
}

void setup() {
  Serial.begin(9600);
  while (!Serial);
  const float z_height = 0.;
  const float shoulderHeight = 116.;
  const float x = 250.;
  const float xUpperLimit = 300.;
  const float yUpperLimit = 380.;
  const float zUpperLimit = 300.;
  Serial.print("z-height: ");
  Serial.println(z_height);
  float endeff_vector = sqrt(square(x) + square(z_height));
  Serial.print("vector length: ");
  Serial.println(endeff_vector);
  float beta_sin = endeff_vector / xUpperLimit;
  Serial.print("half beta in sine: ");
  Serial.println(beta_sin);
  float beta = 2 * asin(beta_sin) * 180 / PI;
  Serial.print("beta: ");
  Serial.println(beta);
}