GY-63_MS5611/libraries/FastTrig/FastTrig.h

98 lines
1.8 KiB
C
Raw Normal View History

2022-12-03 06:59:56 -05:00
#pragma once
2021-01-29 06:31:58 -05:00
//
// FILE: FastTrig.h
// AUTHOR: Rob Tillaart
2022-12-22 07:44:04 -05:00
// VERSION: 0.3.2
2021-01-29 06:31:58 -05:00
// PURPOSE: Arduino library for a faster approximation of sin() and cos()
// DATE: 2011-08-18
// URL: https://github.com/RobTillaart/FastTrig
// https://forum.arduino.cc/index.php?topic=69723.0
2021-04-25 13:56:44 -04:00
2021-01-29 06:31:58 -05:00
2022-12-03 06:59:56 -05:00
#ifdef ESP_PLATFORM
#include <math.h>
#include <stdint.h>
#include <stdbool.h>
#else
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
2022-12-03 06:59:56 -05:00
#endif
2021-01-29 06:31:58 -05:00
2022-11-07 04:20:54 -05:00
2022-12-22 07:44:04 -05:00
#define FAST_TRIG_LIB_VERSION (F("0.3.2"))
2022-04-15 10:43:05 -04:00
2022-12-03 06:59:56 -05:00
#ifdef __cplusplus
extern "C"
{
#endif
extern uint16_t sinTable16[];
extern uint8_t sinTable8[];
2021-01-29 06:31:58 -05:00
2021-12-18 07:14:58 -05:00
2022-12-17 09:04:42 -05:00
///////////////////////////////////////////////////////
//
// GONIO INT EXPERIMENTAL
//
int isin256(uint32_t v);
int icos256(uint32_t v);
// calculate both in one call.
2022-12-22 07:44:04 -05:00
void isincos256(uint32_t v, int *si, int *co);
2022-12-17 09:04:42 -05:00
2021-01-29 06:31:58 -05:00
///////////////////////////////////////////////////////
//
// GONIO LOOKUP
//
2022-04-15 10:43:05 -04:00
float isin(float f);
2021-01-29 06:31:58 -05:00
2022-04-15 10:43:05 -04:00
float icos(float x);
2021-12-18 07:14:58 -05:00
2022-12-17 09:04:42 -05:00
// calculate both in one call.
2022-12-22 07:44:04 -05:00
void isincos(float v, float *si, float *co);
2022-12-17 09:04:42 -05:00
2022-04-15 10:43:05 -04:00
float itan(float f);
2021-08-10 15:24:22 -04:00
2022-12-03 06:59:56 -05:00
// 0 returns NAN but we have a icot(x) cotangent.
2022-04-15 10:43:05 -04:00
float icot(float f);
2021-08-10 15:24:22 -04:00
2021-01-29 06:31:58 -05:00
///////////////////////////////////////////////////////
//
2022-12-03 06:59:56 -05:00
// INVERSE GONIO LOOKUP
2021-01-29 06:31:58 -05:00
//
2022-04-15 10:43:05 -04:00
float iasin(float f);
float iacos(float f);
2022-12-08 11:32:53 -05:00
// PLACEHOLDER (might be obsolete due to atanFast() formula.
2022-04-15 10:43:05 -04:00
float iatan(float f);
2021-01-29 06:31:58 -05:00
2022-12-08 11:32:53 -05:00
// fast atan() formula, in fact a modified Taylor expansion
// input = -1 .. 1
float atanFast(float f);
inline float atanHelper(float x);
// atan2Fast() folds and mirrors => calls atanFast() + offset.
float atan2Fast(float y, float x);
2021-12-18 07:14:58 -05:00
2022-12-18 10:36:10 -05:00
///////////////////////////////////////////////////////
//
// HYPOT
// related but not strict gonio.
//
// hypotFast() formula for faster hypot() at the price of accuracy
// experimental!
float hypotFast(float x, float y);
2022-12-03 06:59:56 -05:00
#ifdef __cplusplus
}
#endif
// -- END OF FILE --