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 fromall commits
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
93 changes: 67 additions & 26 deletionsapi/Common.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,20 +37,63 @@ typedef enum {
#define SERIAL 0x0
#define DISPLAY 0x1

#ifndef constrain
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#endif

#ifndef radians
#define radians(deg) ((deg)*DEG_TO_RAD)
#endif
#ifdef __cplusplus
} // extern "C"

#ifndef degrees
#define degrees(rad) ((rad)*RAD_TO_DEG)
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>
auto radians(const T& deg) -> decltype(deg * DEG_TO_RAD)
{
return deg * DEG_TO_RAD;
}

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

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); })
#endif

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

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

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

#ifndef sq
#define sq(x) ((x)*(x))
#ifdef __cplusplus
extern "C" {
#endif

typedef void (*voidFuncPtr)(void);
Expand DownExpand Up@@ -117,33 +160,31 @@ void loop(void);

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

#ifdef __cplusplus
template<class T, class L>
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>
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
#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 Down

[8]ページ先頭

©2009-2025 Movatter.jp