Project Euler Solutions
Macros
macros.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CL_COMPILER   0
 Indicates whether the code is being compiled under the Visual Studios compiler This is guaranteed to be either 0 or 1. More...
 
#define CLANG_COMPILER   0
 Indicates whether the code is being compiled under the clang compiler This is guaranteed to be either 0 or 1. More...
 
#define GCC_COMPILER   0
 Indicates whether the code is being compiled under the GCC compiler This is guaranteed to be either 0 or 1. More...
 
#define INTEL_COMPILER   0
 Indicates whether the code is being compiled under the Intel optimized compiler This is guaranteed to be either 0 or 1. More...
 
#define AMD_COMPILER   0
 Indicates whether the code is being compiled under the AMD optimized compiler. More...
 
#define X64_COMPILER   0
 Indicates whether the code is being compiled for an amd64 or x86_64 machine This is guaranteed to be either 0 or 1. More...
 
#define X86_COMPILER   0
 Indicates whether the code is being compiled for an x86 machine. More...
 
#define ARM_COMPILER   0
 Indicates whether the code is being compiled for an ARM machine (regardless of 32 or 64 bit) This is guaranteed to be either 0 or 1. More...
 
#define ARM_THUMB   0
 Indicates whether the code is being compiled for ARM thumb mode This is guaranteed to be either 0 or 1. More...
 
#define max(a, b)   (((a) > (b)) ? (a) : (b))
 Given two comparable variables, return the greater. More...
 
#define min(a, b)   (((a) < (b)) ? (a) : (b))
 Given two comparable variables, return the lesser. More...
 
#define swap(x, y, T)   do { T SWAP = x; x = y; y = SWAP; } while (0)
 Given two similary-typed variables and their type, swap them. More...
 
#define likely(x)   __builtin_expect(!!(x), 1)
 Indicates to the compiler (if supported) that this branch is likely to occur and it should arrange code accordingly. More...
 
#define unlikely(x)   __builtin_expect(!!(x), 0)
 Indicates to the compiler (if supported) that this branch is unlikely to occur and it should arrange code accordingly. More...
 
#define PACK(decl)   decl __attribute__((__packed__))
 Indicates to the compiler that the structure defined within should be packed bitwise. More...
 
#define EXTERN_PRINTF   extern int printf(const char *const _Format, ...)
 Denotes that printf is referenced in this header, but does not require including stdio.h. More...
 
#define PCC_SQRT_ACCURACY   8
 When on PCC, sqrt() has to be re-implemented. More...
 
#define MAX_FACTORIAL_64   20
 This macro denotes the number that, when factorialed, can be stored in a 64-bit unsigned integer. More...
 
#define MAX_FACTORIAL_128   34
 This macro denotes the number that, when factorialed, can be stored in a 64-bit unsigned integer. More...
 
#define MAX_POW_10_16   10000U
 This macro denotes the largest power of 10 that can be stored in a 16-bit unsigned integer. More...
 
#define POW_OF_MAX_POW_10_16   4
 This macro defines the power of MAX_POW_10_16. More...
 
#define MAX_POW_10_32   1000000000UL
 This macro denotes the largest power of 10 that can be stored in a 32-bit unsigned integer. More...
 
#define POW_OF_MAX_POW_10_32   9
 This macro defines the power of MAX_POW_10_32. More...
 
#define MAX_POW_10_64   10000000000000000000ULL
 This macro denotes the largest power of 10 that can be stored in a 64-bit unsigned integer. More...
 
#define POW_OF_MAX_POW_10_64   19
 This macro defines the power of MAX_POW_10_64. More...
 
#define MAX_POW_10_128   ((uintmax_t) MAX_POW_10_64 * (uintmax_t) MAX_POW_10_64)
 This macro denotes the largest power of 10 that can be stored in a 128-bit unsigned integer. More...
 
#define POW_OF_MAX_POW_10_128   38
 This macro defines the power of MAX_POW_10_128. More...
 
#define MACROS_H
 
#define CL_COMPILER   0
 
#define CLANG_COMPILER   0
 
#define GCC_COMPILER   0
 
#define INTEL_COMPILER   0
 
#define X64_COMPILER   0
 
#define X86_COMPILER   0
 
#define ARM_COMPILER   0
 
#define ARM_THUMB   0
 
#define swap(x, y, T)   do { T SWAP = x; x = y; y = SWAP; } while (0)
 
#define likely(x)   __builtin_expect(!!(x), 1)
 
#define unlikely(x)   __builtin_expect(!!(x), 0)
 
#define PACK(decl)   decl __attribute__((__packed__))
 
#define EXTERN_PRINTF   extern int printf(const char *const _Format, ...)
 
#define PCC_SQRT_ACCURACY   8
 
#define MAX_FACTORIAL_64   20
 
#define MAX_FACTORIAL_128   34
 
#define MAX_POW_10_16   10000U
 
#define POW_OF_MAX_POW_10_16   4
 
#define MAX_POW_10_32   1000000000UL
 
#define POW_OF_MAX_POW_10_32   9
 
#define MAX_POW_10_64   10000000000000000000ULL
 
#define POW_OF_MAX_POW_10_64   19
 
#define MAX_POW_10_128   ((uintmax_t) MAX_POW_10_64 * (uintmax_t) MAX_POW_10_64)
 
#define POW_OF_MAX_POW_10_128   38
 

Macro Definition Documentation

#define AMD_COMPILER   0

Indicates whether the code is being compiled under the AMD optimized compiler.

Attention
The macro suite can't actually detect the difference between clang and aocc, so the user needs to specify

This is guaranteed to be 0 if you don't define it explicitly

#define ARM_COMPILER   0

Indicates whether the code is being compiled for an ARM machine (regardless of 32 or 64 bit) This is guaranteed to be either 0 or 1.

#define ARM_COMPILER   0
#define ARM_THUMB   0

Indicates whether the code is being compiled for ARM thumb mode This is guaranteed to be either 0 or 1.

#define ARM_THUMB   0
#define CL_COMPILER   0

Indicates whether the code is being compiled under the Visual Studios compiler This is guaranteed to be either 0 or 1.

#define CL_COMPILER   0
#define CLANG_COMPILER   0

Indicates whether the code is being compiled under the clang compiler This is guaranteed to be either 0 or 1.

#define CLANG_COMPILER   0
#define EXTERN_PRINTF   extern int printf(const char *const _Format, ...)

Denotes that printf is referenced in this header, but does not require including stdio.h.

#define EXTERN_PRINTF   extern int printf(const char *const _Format, ...)
#define GCC_COMPILER   0

Indicates whether the code is being compiled under the GCC compiler This is guaranteed to be either 0 or 1.

#define GCC_COMPILER   0
#define INTEL_COMPILER   0

Indicates whether the code is being compiled under the Intel optimized compiler This is guaranteed to be either 0 or 1.

#define INTEL_COMPILER   0
#define likely (   x)    __builtin_expect(!!(x), 1)
#define likely (   x)    __builtin_expect(!!(x), 1)

Indicates to the compiler (if supported) that this branch is likely to occur and it should arrange code accordingly.

Parameters
x
Returns
The truth value of x
Note
If the compiler does not support this feature, the macro does nothing and just returns x
#define MACROS_H
#define max (   a,
 
)    (((a) > (b)) ? (a) : (b))

Given two comparable variables, return the greater.

Parameters
aAn object to compare
bAn object to compare
Returns
The greater of a and b
#define MAX_FACTORIAL_128   34

This macro denotes the number that, when factorialed, can be stored in a 64-bit unsigned integer.

#define MAX_FACTORIAL_128   34
#define MAX_FACTORIAL_64   20

This macro denotes the number that, when factorialed, can be stored in a 64-bit unsigned integer.

#define MAX_FACTORIAL_64   20
#define MAX_POW_10_128   ((uintmax_t) MAX_POW_10_64 * (uintmax_t) MAX_POW_10_64)
#define MAX_POW_10_128   ((uintmax_t) MAX_POW_10_64 * (uintmax_t) MAX_POW_10_64)

This macro denotes the largest power of 10 that can be stored in a 128-bit unsigned integer.

#define MAX_POW_10_16   10000U

This macro denotes the largest power of 10 that can be stored in a 16-bit unsigned integer.

#define MAX_POW_10_16   10000U
#define MAX_POW_10_32   1000000000UL
#define MAX_POW_10_32   1000000000UL

This macro denotes the largest power of 10 that can be stored in a 32-bit unsigned integer.

#define MAX_POW_10_64   10000000000000000000ULL
#define MAX_POW_10_64   10000000000000000000ULL

This macro denotes the largest power of 10 that can be stored in a 64-bit unsigned integer.

#define min (   a,
 
)    (((a) < (b)) ? (a) : (b))

Given two comparable variables, return the lesser.

Parameters
aAn object to compare
bAn object to compare
Returns
The lesser of a and b
#define PACK (   decl)    decl __attribute__((__packed__))
#define PACK (   decl)    decl __attribute__((__packed__))

Indicates to the compiler that the structure defined within should be packed bitwise.

Parameters
declA struct declaration
Note
Unlike simply saying attribute((packed)), this is supporeted on CL as well
#define PCC_SQRT_ACCURACY   8
#define PCC_SQRT_ACCURACY   8

When on PCC, sqrt() has to be re-implemented.

This controls the number of loops that happens in that case.

#define POW_OF_MAX_POW_10_128   38

This macro defines the power of MAX_POW_10_128.

In other words, \(\10^{\texttt{POW_OF_MAX_POW_10_128}} = \texttt{MAX_POW_10_128}\)

#define POW_OF_MAX_POW_10_128   38
#define POW_OF_MAX_POW_10_16   4

This macro defines the power of MAX_POW_10_16.

In other words, \(\10^{\texttt{POW_OF_MAX_POW_10_16}} = \texttt{MAX_POW_10_16}\)

#define POW_OF_MAX_POW_10_16   4
#define POW_OF_MAX_POW_10_32   9

This macro defines the power of MAX_POW_10_32.

In other words, \(\10^{\texttt{POW_OF_MAX_POW_10_32}} = \texttt{MAX_POW_10_32}\)

#define POW_OF_MAX_POW_10_32   9
#define POW_OF_MAX_POW_10_64   19

This macro defines the power of MAX_POW_10_64.

In other words, \(\10^{\texttt{POW_OF_MAX_POW_10_64}} = \texttt{MAX_POW_10_64}\)

#define POW_OF_MAX_POW_10_64   19
#define swap (   x,
  y,
 
)    do { T SWAP = x; x = y; y = SWAP; } while (0)

Given two similary-typed variables and their type, swap them.

Given two comparable variables, return the greater.

Parameters
xA variable to swap
yA variable to swap
TThe type of x and y
aAn object to compare
bAn object to compare
Returns
The greater of a and b Given two comparable variables, return the lesser
Parameters
aAn object to compare
bAn object to compare
Returns
The lesser of a and b Given two similary-typed variables and their type, swap them
Parameters
xA variable to swap
yA variable to swap
TThe type of x and y
#define swap (   x,
  y,
 
)    do { T SWAP = x; x = y; y = SWAP; } while (0)
#define unlikely (   x)    __builtin_expect(!!(x), 0)
#define unlikely (   x)    __builtin_expect(!!(x), 0)

Indicates to the compiler (if supported) that this branch is unlikely to occur and it should arrange code accordingly.

Parameters
x
Returns
The truth value of x
Note
If the compiler does not support this feature, the macro does nothing and just returns x
#define X64_COMPILER   0

Indicates whether the code is being compiled for an amd64 or x86_64 machine This is guaranteed to be either 0 or 1.

Indicates whether the code is being compiled under the AMD optimized compiler.

Attention
The macro suite can't actually detect the difference between clang and aocc, so the user needs to specify

This is guaranteed to be 0 if you don't define it explicitly Indicates whether the code is being compiled for an amd64 or x86_64 machine This is guaranteed to be either 0 or 1

#define X64_COMPILER   0
#define X86_COMPILER   0
#define X86_COMPILER   0

Indicates whether the code is being compiled for an x86 machine.

Note
If being compiled for amd64/x86_64 this will be falsey

This is guaranteed to be either 0 or 1