esp32-sk6812/include/fasttrigon.h

40 lines
993 B
C
Raw Normal View History

2019-12-02 22:42:31 +01:00
/*!
* \file
*
* This file contains function prototypes for very fast lookup-table based
* trigonometric functions.
*
* The functions take an argument that is dependent on the lookup-table size
* (LUT_SIZE). LUT_SIZE corresponds to 2π. Values outside the range
* [0..LUT_SIZE] are supported and interpreted normally, so just replace 2π
* with LUT_SIZE and you're done.
*/
#pragma once
#include <cstdint>
#define FASTTRIGON_8BIT(x) ((x) >> (fasttrigon::PRECISION_BITS - 8))
2019-12-02 22:42:31 +01:00
namespace fasttrigon {
static const uint32_t LUT_SIZE = 2048;
static const uint32_t PRECISION_BITS = 11;
static const int32_t SCALE = 1023;
static const uint32_t UNIT_SHIFT = PRECISION_BITS-1;
2019-12-02 22:42:31 +01:00
/*!
* \returns 127 * sin(2π * arg / LUT_SIZE)
*/
int32_t fastsin(int32_t arg);
/*!
* \returns 127 * cos(2π * arg / LUT_SIZE)
*/
int32_t fastcos(int32_t arg);
/*!
* \returns 127 * tan(2π * arg / LUT_SIZE)
*/
int32_t fasttan(int32_t arg);
}