Smarter MIN, MAX, ABS macros
Use macros that explicitly avoid double-evaluation and can be used for any datatype, replacing `min`, `max`, `abs`, `fabs`, `labs`, and `FABS`. Co-Authored-By: ejtagle <ejtagle@hotmail.com>
This commit is contained in:
@ -84,7 +84,7 @@ void swSpiBegin(const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin)
|
||||
uint8_t swSpiInit(const uint8_t spiRate, const pin_t sck_pin, const pin_t mosi_pin) {
|
||||
WRITE(mosi_pin, HIGH);
|
||||
WRITE(sck_pin, LOW);
|
||||
return (SystemCoreClock == 120000000 ? 44 : 38) / POW(2, 6 - min(spiRate, 6));
|
||||
return (SystemCoreClock == 120000000 ? 44 : 38) / POW(2, 6 - MIN(spiRate, 6));
|
||||
}
|
||||
|
||||
#endif // TARGET_LPC1768
|
||||
|
@ -50,9 +50,11 @@ typedef uint8_t byte;
|
||||
#define PSTR(v) (v)
|
||||
#define PGM_P const char *
|
||||
|
||||
// Used for libraries, preprocessor, and constants
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
|
||||
#ifndef isnan
|
||||
#define isnan std::isnan
|
||||
#endif
|
||||
@ -60,11 +62,6 @@ typedef uint8_t byte;
|
||||
#define isinf std::isinf
|
||||
#endif
|
||||
|
||||
//not constexpr until c++14
|
||||
//#define max(v1, v2) std::max((int)v1,(int)v2)
|
||||
//#define min(v1, v2) std::min((int)v1,(int)v2)
|
||||
//#define abs(v) std::abs(v)
|
||||
|
||||
#define sq(v) ((v) * (v))
|
||||
#define square(v) sq(v)
|
||||
#define constrain(value, arg_min, arg_max) ((value) < (arg_min) ? (arg_min) :((value) > (arg_max) ? (arg_max) : (value)))
|
||||
|
Reference in New Issue
Block a user