Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Arduino compatibility with the STL (min and max macro) #399

Closed
wants to merge 6 commits into from
Closed
Changes from 1 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
10 changes: 9 additions & 1 deletion cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void loop( void ) ;
#include "WMath.h"
#include "HardwareSerial.h"
#include "pulse.h"
#include <bits/stl_algobase.h>
#endif
#include "delay.h"
#ifdef __cplusplus
Expand All @@ -92,6 +93,7 @@ void loop( void ) ;
#include "wiring_shift.h"
#include "WInterrupts.h"

#ifndef __cplusplus
// undefine stdlib's abs if encountered
#ifdef abs
#undef abs
Expand All @@ -100,8 +102,14 @@ void loop( void ) ;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#else
using std::min;
prototypicalpro marked this conversation as resolved.
Show resolved Hide resolved
using std::max;
prototypicalpro marked this conversation as resolved.
Show resolved Hide resolved

prototypicalpro marked this conversation as resolved.
Show resolved Hide resolved
#endif

#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))
Expand Down