#ifndef __MY_MATH_H_
#define __MY_MATH_H_

#include "stdint.h"

#define BIT_REVERSED(data)                                      \
    ({                                                          \
        typeof(data) _result = 0;                               \
        for(uint8_t i = 0; i < sizeof(typeof(data)) * 8; i++)   \
        {                                                       \
            _result = ((data >> i) & 0x01) | _result;           \
            if(i < (sizeof(typeof(data)) * 8 - 1))              \
            {                                                   \
                _result = _result << 1;                         \
            }                                                   \
        }                                                       \
        _result;                                                \
    })

#define MAX(x, y)                                               \
({                                                              \
    typeof(x) _max1 = (x);                                      \
    typeof(y) _max2 = (y);                                      \
    (void)(&_max1 == &_max2);                                   \
    _max1 > _max2 ? _max1 : _max2                               \
})

#define MIN(x, y)                                               \
({                                                              \
    typeof(x) _min1 = x;                                        \
    typeof(y) _min2 = y;                                        \
    (void)(&_min1 == &_min2);                                   \
    _min1 < _min2 ? _min1 : _min2                               \
})

#define OVER_WEIGHT_SCALE 1.2f/9.8f			//假设a = 1.2
#define LOSS_WEIGHT_SCALE -1.2f/9.8f	

void Least_Squares(uint8_t n, float x[], uint32_t y[], float* slope, float* intercept);

void buf2int(int *tint, unsigned char *buf);

float average(int n_values, ...);

// uint8_t Bit_Reversed(uint8_t data);

#endif
