CLibs
Loading...
Searching...
No Matches
simple_math.h File Reference
#include "attributes.h"
#include "extra_types.h"

Go to the source code of this file.

Macros

#define sign_flipped(SIGN)
#define min_m(NUM_A, NUM_B)
#define max_m(NUM_A, NUM_B)

Enumerations

enum  sign_t { SIGN_NEG = -1 , SIGN_POS = 1 }
 The signs are equal to their supposed value. More...

Functions

LibraryDefined Mathematical signed sgn_64 (const int64_t n)
LibraryDefined Mathematical int64_t min_i64 (const int64_t a, const int64_t b)
LibraryDefined Mathematical uint64_t min_u64 (const uint64_t a, const uint64_t b)
LibraryDefined Mathematical int64_t max_i64 (const int64_t a, const int64_t b)
LibraryDefined Mathematical uint64_t max_u64 (const uint64_t a, const uint64_t b)
LibraryDefined Mathematical bool is_within (const int64_t low, const int64_t num, const int64_t high)
LibraryDefined Mathematical bool is_power_of_two (const uint64_t num)
 Returns true if num is a power of two.

Macro Definition Documentation

◆ max_m

#define max_m ( NUM_A,
NUM_B )
Value:
( ( NUM_A ) > ( NUM_B ) ? ( NUM_A ) : ( NUM_B ) )

Evaluates to the bigger of the two numbers. Works with both integral and floating-point types with some caveats (see below).

Attention
constructs with the ++, --, +=, -=, ... operators like
int a = 10, b = 10;
int c = max_m( a++, b );
#define max_m(NUM_A, NUM_B)
Definition simple_math.h:63
are undefined for this macro.

This isn't the case for the (min|max)_[ui]64 functions

◆ min_m

#define min_m ( NUM_A,
NUM_B )
Value:
( ( NUM_A ) < ( NUM_B ) ? ( NUM_A ) : ( NUM_B ) )

Evaluates to the smaller of the two numbers. Works with both integral and floating-point types with some caveats (see below).

Attention
constructs with the ++, --, +=, -=, ... operators like
int a = 10, b = 10;
int c = min_m( a++, b );
#define min_m(NUM_A, NUM_B)
Definition simple_math.h:49
are undefined for this macro.

This isn't the case for the (min|max)_[ui]64 functions

◆ sign_flipped

#define sign_flipped ( SIGN)
Value:
( -( SIGN ) )
Returns
1 if sign was -1 and vice versa
See also
sign_t

Enumeration Type Documentation

◆ sign_t

enum sign_t

The signs are equal to their supposed value.

Enumerator
SIGN_NEG 
SIGN_POS 

Function Documentation

◆ is_power_of_two()

LibraryDefined Mathematical bool is_power_of_two ( const uint64_t num)
inline

Returns true if num is a power of two.

◆ is_within()

LibraryDefined Mathematical bool is_within ( const int64_t low,
const int64_t num,
const int64_t high )
inline

Tests if num is within the specified bounds.

low should obviously be smaller than high

Parameters
lowlower bound
numtested number
highupper bound
Returns
true if low <= num <= high

◆ max_i64()

LibraryDefined Mathematical int64_t max_i64 ( const int64_t a,
const int64_t b )
inline

◆ max_u64()

LibraryDefined Mathematical uint64_t max_u64 ( const uint64_t a,
const uint64_t b )
inline

◆ min_i64()

LibraryDefined Mathematical int64_t min_i64 ( const int64_t a,
const int64_t b )
inline

◆ min_u64()

LibraryDefined Mathematical uint64_t min_u64 ( const uint64_t a,
const uint64_t b )
inline

◆ sgn_64()

LibraryDefined Mathematical signed sgn_64 ( const int64_t n)
inline

Sign ( -1, 0, 1 ) of the number