Last active
December 24, 2015 17:19
-
-
Save monkeydom/6834787 to your computer and use it in GitHub Desktop.
MIN and MAX definitions starting with iOS 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if __clang__ | |
#define __NSX_PASTE__(A,B) A##B | |
#if !defined(MIN) | |
#define __NSMIN_IMPL__(A,B,L) ({ __typeof__(A) __NSX_PASTE__(__a,L) = (A); __typeof__(B) __NSX_PASTE__(__b,L) = (B); (__NSX_PASTE__(__a,L) < __NSX_PASTE__(__b,L)) ? __NSX_PASTE__(__a,L) : __NSX_PASTE__(__b,L); }) | |
#define MIN(A,B) __NSMIN_IMPL__(A,B,__COUNTER__) | |
#endif | |
#if !defined(MAX) | |
#define __NSMAX_IMPL__(A,B,L) ({ __typeof__(A) __NSX_PASTE__(__a,L) = (A); __typeof__(B) __NSX_PASTE__(__b,L) = (B); (__NSX_PASTE__(__a,L) < __NSX_PASTE__(__b,L)) ? __NSX_PASTE__(__b,L) : __NSX_PASTE__(__a,L); }) | |
#define MAX(A,B) __NSMAX_IMPL__(A,B,__COUNTER__) | |
#endif | |
#if !defined(ABS) | |
#define __NSABS_IMPL__(A,L) ({ __typeof__(A) __NSX_PASTE__(__a,L) = (A); (__NSX_PASTE__(__a,L) < 0) ? - __NSX_PASTE__(__a,L) : __NSX_PASTE__(__a,L); }) | |
#define ABS(A) __NSABS_IMPL__(A,__COUNTER__) | |
#endif | |
#else | |
#if !defined(MIN) | |
#define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; }) | |
#endif | |
#if !defined(MAX) | |
#define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) | |
#endif | |
#if !defined(ABS) | |
#define ABS(A) ({ __typeof__(A) __a = (A); __a < 0 ? -__a : __a; }) | |
#endif | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment