Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update math macros to avoid computing callable arguments more than once#140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Keating950 wants to merge4 commits intoarduino:master
base:master
Choose a base branch
Loading
fromKeating950:master
Open
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
minimize diff; fix missing paren
  • Loading branch information
@Keating950
Keating950 committedFeb 17, 2021
commit18f50953c4644b2c5cb90f20cf9f7427ece02647
96 changes: 46 additions & 50 deletionsapi/Common.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,92 +37,63 @@ typedef enum {
#define SERIAL 0x0
#define DISPLAY 0x1

#ifdef __cplusplus
} // extern "C"
#endif

#ifdef __cplusplus
} // extern "C"

template<class T, class L>
auto min(const T& a, const L& b) -> decltype(b < a ? b : a)
{
return (b < a) ? b : a;
}

template<class T, class L>
auto max(const T& a, const L& b) -> decltype(b < a ? b : a)
{
return (a < b) ? b : a;
}


template<class T, class U, class V>
template<class T, class U, class V>
auto constrain(const T& amt, const U& low, const V& high) -> decltype(amt < low ? low : (amt > high ? high : amt))
{
return amt < low ? low : (amt > high ? high : amt);
}
template<class T>

template<class T>
auto radians(const T& deg) -> decltype(deg * DEG_TO_RAD)
{
return deg * DEG_TO_RAD;
}

template<class T>
template<class T>
auto degrees(const T& rad) -> decltype(rad * RAD_TO_DEG)
{
return rad * RAD_TO_DEG;
}

template<class T>
template<class T>
auto sq(const T& x) -> decltype(x*x)
{
return x*x;
}
#else
#ifndef constrain
#define constrain(amt,low,high) \
({ __typeof__ (amt) _amt = (amt); \
__typeof__ (low) _low = (low); \
__typeof__ (high) _high = (high); \
_amt < _low ? _low : (_amt > _high ? _high :_amt); }
({ __typeof__ (amt) _amt = (amt); \
__typeof__ (low) _low = (low); \
__typeof__ (high) _high = (high); \
_amt < _low ? _low : (_amt > _high ? _high :_amt); })
#endif

#ifndef radians
#define radians(deg) \
({ __typeof__ (deg) _deg = deg; \
_deg * DEG_TO_RAD; })
({ __typeof__ (deg) _deg = deg; \
_deg * DEG_TO_RAD; })
#endif

#ifndef degrees
#define degrees(rad) \
({ __typeof__ (rad) _rad = rad; \
_rad * RAD_TO_DEG; })
({ __typeof__ (rad) _rad = rad; \
_rad * RAD_TO_DEG; })
#endif

#ifndef sq
#define sq(x) \
({ __typeof__ (x) _x = x; \
_x * _x; })
#endif

#ifndef min
#define min(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
#endif

#ifndef max
#define max(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
({ __typeof__ (x) _x = x; \
_x * _x; })
#endif
#endif

#ifdef __cplusplus
extern "C"{
extern "C"{
#endif

typedef void (*voidFuncPtr)(void);
Expand DownExpand Up@@ -189,8 +160,32 @@ void loop(void);

#ifdef __cplusplus
} // extern "C"
#endif

template<class T, class L>
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
{
return (b < a) ? b : a;
}

template<class T, class L>
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
{
return (a < b) ? b : a;
}
#else
#ifndef min
#define min(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
#endif
#ifndef max
#define max(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#endif
#endif

#ifdef __cplusplus

Expand All@@ -213,3 +208,4 @@ void randomSeed(unsigned long);
long map(long, long, long, long, long);

#endif // __cplusplus


[8]ページ先頭

©2009-2025 Movatter.jp