Skip to content
gicking edited this page Feb 10, 2018 · 3 revisions

back to Command Reference / Math

Description

Calculates the arccosine (in radians) of an argument. The result will be between 0 and PI (see constants.

Note: for conversion radians to degrees, use deg2rad().

Inclusion

  • defined in misc.h
  • auto-loaded in main_general.h
  • no #define required

Syntax

a = acos(x)

Parameters

  • input:

    • x: number to calculate arccosine for (float)
  • output:

    • none

Returns

  • The arccosine of the argument (float).

Example Code

The below code prints a table for y=acos(x) between -1..1 in degrees. Note that the example requires option #define USE_FTOA in file config.h for floating point output.

#include "main_general.h"
#include "uart1.h"
#include "putchar.h"

void setup() {

  float x,y;
  char  s1[20], s2[20];
  
  // init UART and printf()
  UART1_begin(115200);
  putcharAttach(UART1_write);
  
  // allow the terminal to launch
  sw_delay(1000);
  
  // print math table
  for (x=-1.0; x<=1.0; x+=0.1) {
    y = rad2deg(acos(x));
    printf("%s  %s\n", floatToString(s1,x,2), floatToString(s2,y,2));
  }
  
}

void loop() {
  // dummy
}

Relevant Tutorial

  • tbd

See also

Clone this wiki locally