1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Arduino UNO 3で三角関数の計算し、ベンチマークする。(単精度浮動小数点)

Posted at

参考

x 過去ログを見よ!!
x ICHIKEN様のホームページの内容を非営利、研究調査目的で引用しました。

結果

o_coq673.jpg

プログラム



//度数で与えられた角度を弧度法に変換し、それをsin, arcsin, cos, arccos, tan, arctanの順で三角関数の計算を行い、それを0~359°まで反復する。
void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.print("START");
  for(int i = 0;i < 9;i++){
    Serial.print('.');
    delay(500); //起動待ち
  }
  Serial.println();
}
float deg_to_rad(float deg) {
  float rad;
  rad = deg * (PI / 180);
  return rad;
}
float rad_to_deg(float rad) {
  float deg;
  deg = rad / (PI / 180);
  return deg;
}
void loop() {
  unsigned long start_time, end_time;
  unsigned long time;
  float rad, deg1, deg2, deg3, t_sum;
  t_sum = 0;
  unsigned int temp;
  int x;
  start_time = millis();
  for (x = 0; x < 100; x++) {
    for (int deg = 0; deg < 360; deg++) {
      rad = deg_to_rad((float)deg);
      deg1 = rad_to_deg(asin(sin(rad)));
      rad = deg_to_rad((float)deg1);
      deg2 = rad_to_deg(acos(cos(rad)));
      rad = deg_to_rad((float)deg2);
      deg3 = rad_to_deg(atan(tan(rad)));
      if( deg3 < 0.0f ) { deg3 = 0.0f - deg3;}
      t_sum = t_sum + deg3;
    }
  }
  end_time = millis();
  time = end_time - start_time;
  Serial.print("END Value:");
  Serial.print(x); //最後の値の出力
  Serial.print('-');
  Serial.print(t_sum); //最適化対策 1から90の足し算91*45=4095 (16380-180)*100
  Serial.print(" rad:");
  Serial.print(rad);
  Serial.print(" deg2:");
  Serial.print(deg2);
  Serial.print(" deg3:");
  Serial.print(deg3);
  Serial.print("\n");
  Serial.print("StartTime:");
  Serial.print(start_time);
  Serial.print(" EndTime:");
  Serial.print(end_time);
  Serial.print(" Time:");
  Serial.println(time);
  delay(3000);
}



1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?