From fb3f82fd7270cf5e1304828844b58cfb0fb79554 Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Wed, 6 Jun 2018 17:48:23 +0100 Subject: [PATCH] Improve operator generation macros (#58) --- src/FixedPoints/SFixedFreeFunctions.h | 69 ++++++++++++++------------- src/FixedPoints/UFixedFreeFunctions.h | 69 ++++++++++++++------------- 2 files changed, 72 insertions(+), 66 deletions(-) diff --git a/src/FixedPoints/SFixedFreeFunctions.h b/src/FixedPoints/SFixedFreeFunctions.h index 3ee33ca..1fe5047 100644 --- a/src/FixedPoints/SFixedFreeFunctions.h +++ b/src/FixedPoints/SFixedFreeFunctions.h @@ -278,43 +278,46 @@ constexpr auto operator /(const SFixed & left, const return (SFixed(left) op right);\ } -#define OPERATORS( opType, op ) \ - opType##_OPERATOR( char, op )\ - opType##_OPERATOR( unsigned char, op )\ - opType##_OPERATOR( signed char, op )\ - opType##_OPERATOR( unsigned short int, op )\ - opType##_OPERATOR( signed short int, op )\ - opType##_OPERATOR( unsigned int, op )\ - opType##_OPERATOR( signed int, op )\ - opType##_OPERATOR( unsigned long int, op )\ - opType##_OPERATOR( signed long int, op )\ - opType##_OPERATOR( unsigned long long int, op )\ - opType##_OPERATOR( signed long long int, op )\ - opType##_OPERATOR( float, op )\ - opType##_OPERATOR( double, op )\ - opType##_OPERATOR( long double, op ) - -#define LOGIC_OPERATORS( op ) OPERATORS( LOGIC, op ) -#define ARITHMETIC_OPERATORS( op ) OPERATORS( ARITHMETIC, op ) - -LOGIC_OPERATORS( == ) -LOGIC_OPERATORS( != ) -LOGIC_OPERATORS( < ) -LOGIC_OPERATORS( > ) -LOGIC_OPERATORS( <= ) -LOGIC_OPERATORS( >= ) - -ARITHMETIC_OPERATORS( + ) -ARITHMETIC_OPERATORS( - ) -ARITHMETIC_OPERATORS( * ) -ARITHMETIC_OPERATORS( / ) +#define LOGIC_OPERATORS( type )\ + LOGIC_OPERATOR( type, == )\ + LOGIC_OPERATOR( type, != )\ + LOGIC_OPERATOR( type, < )\ + LOGIC_OPERATOR( type, <= )\ + LOGIC_OPERATOR( type, > )\ + LOGIC_OPERATOR( type, >= ) + +#define ARITHMETIC_OPERATORS( type ) \ + ARITHMETIC_OPERATOR( type, + )\ + ARITHMETIC_OPERATOR( type, - )\ + ARITHMETIC_OPERATOR( type, * )\ + ARITHMETIC_OPERATOR( type, / ) + +#define OPERATORS( type ) \ + LOGIC_OPERATORS( type )\ + ARITHMETIC_OPERATORS( type ) + +OPERATORS( float ) +OPERATORS( double ) +OPERATORS( long double ) + +OPERATORS( char ) +OPERATORS( unsigned char ) +OPERATORS( signed char ) +OPERATORS( unsigned short int ) +OPERATORS( signed short int ) +OPERATORS( unsigned int ) +OPERATORS( signed int ) +OPERATORS( unsigned long int ) +OPERATORS( signed long int ) +OPERATORS( unsigned long long int ) +OPERATORS( signed long long int ) // Prevent Macro-bleed: -#undef LOGIC_OPERATOR -#undef ARITHMETIC_OPERATOR #undef OPERATORS -#undef LOGIC_OPERATORS #undef ARITHMETIC_OPERATORS +#undef LOGIC_OPERATORS +#undef ARITHMETIC_OPERATOR +#undef LOGIC_OPERATOR FIXED_POINTS_END_NAMESPACE \ No newline at end of file diff --git a/src/FixedPoints/UFixedFreeFunctions.h b/src/FixedPoints/UFixedFreeFunctions.h index 32eecaa..55b042e 100644 --- a/src/FixedPoints/UFixedFreeFunctions.h +++ b/src/FixedPoints/UFixedFreeFunctions.h @@ -278,43 +278,46 @@ constexpr auto operator /(const UFixed & left, const return (UFixed(left) op right);\ } -#define OPERATORS( opType, op ) \ - opType##_OPERATOR( char, op )\ - opType##_OPERATOR( unsigned char, op )\ - opType##_OPERATOR( signed char, op )\ - opType##_OPERATOR( unsigned short int, op )\ - opType##_OPERATOR( signed short int, op )\ - opType##_OPERATOR( unsigned int, op )\ - opType##_OPERATOR( signed int, op )\ - opType##_OPERATOR( unsigned long int, op )\ - opType##_OPERATOR( signed long int, op )\ - opType##_OPERATOR( unsigned long long int, op )\ - opType##_OPERATOR( signed long long int, op )\ - opType##_OPERATOR( float, op )\ - opType##_OPERATOR( double, op )\ - opType##_OPERATOR( long double, op ) - -#define LOGIC_OPERATORS( op ) OPERATORS( LOGIC, op ) -#define ARITHMETIC_OPERATORS( op ) OPERATORS( ARITHMETIC, op ) - -LOGIC_OPERATORS( == ) -LOGIC_OPERATORS( != ) -LOGIC_OPERATORS( < ) -LOGIC_OPERATORS( > ) -LOGIC_OPERATORS( <= ) -LOGIC_OPERATORS( >= ) - -ARITHMETIC_OPERATORS( + ) -ARITHMETIC_OPERATORS( - ) -ARITHMETIC_OPERATORS( * ) -ARITHMETIC_OPERATORS( / ) +#define LOGIC_OPERATORS( type )\ + LOGIC_OPERATOR( type, == )\ + LOGIC_OPERATOR( type, != )\ + LOGIC_OPERATOR( type, < )\ + LOGIC_OPERATOR( type, <= )\ + LOGIC_OPERATOR( type, > )\ + LOGIC_OPERATOR( type, >= ) + +#define ARITHMETIC_OPERATORS( type ) \ + ARITHMETIC_OPERATOR( type, + )\ + ARITHMETIC_OPERATOR( type, - )\ + ARITHMETIC_OPERATOR( type, * )\ + ARITHMETIC_OPERATOR( type, / ) + +#define OPERATORS( type ) \ + LOGIC_OPERATORS( type )\ + ARITHMETIC_OPERATORS( type ) + +OPERATORS( float ) +OPERATORS( double ) +OPERATORS( long double ) + +OPERATORS( char ) +OPERATORS( unsigned char ) +OPERATORS( signed char ) +OPERATORS( unsigned short int ) +OPERATORS( signed short int ) +OPERATORS( unsigned int ) +OPERATORS( signed int ) +OPERATORS( unsigned long int ) +OPERATORS( signed long int ) +OPERATORS( unsigned long long int ) +OPERATORS( signed long long int ) // Prevent Macro-bleed: -#undef LOGIC_OPERATOR -#undef ARITHMETIC_OPERATOR #undef OPERATORS -#undef LOGIC_OPERATORS #undef ARITHMETIC_OPERATORS +#undef LOGIC_OPERATORS +#undef ARITHMETIC_OPERATOR +#undef LOGIC_OPERATOR FIXED_POINTS_END_NAMESPACE \ No newline at end of file