1 #ifndef INCLUDED_ObjexxFCL_Fmath_hh
2 #define INCLUDED_ObjexxFCL_Fmath_hh
38 min(
short int const a,
short int const b )
40 return ( a < b ? a : b );
49 return ( a < b ? a : b );
56 min(
long int const a,
long int const b )
58 return ( a < b ? a : b );
65 min(
unsigned short int const a,
unsigned short int const b )
67 return ( a < b ? a : b );
74 min(
unsigned int const a,
unsigned int const b )
76 return ( a < b ? a : b );
83 min(
unsigned long int const a,
unsigned long int const b )
85 return ( a < b ? a : b );
92 min(
float const a,
float const b )
94 return ( a < b ? a : b );
101 min(
double const a,
double const b )
103 return ( a < b ? a : b );
110 min(
long double const a,
long double const b )
112 return ( a < b ? a : b );
121 template<
typename T >
126 return ( a < b ? ( a < c ? a : c ) : ( b < c ? b : c ) );
131 template<
typename T >
134 min(
T const &
a,
T const &
b,
T const & c,
T const & d )
141 template<
typename T >
144 min(
T const &
a,
T const &
b,
T const & c,
T const & d,
T const & e )
151 template<
typename T >
154 min(
T const &
a,
T const &
b,
T const & c,
T const & d,
T const & e,
T const &
f )
166 max(
short int const a,
short int const b )
168 return ( a < b ? b : a );
177 return ( a < b ? b : a );
184 max(
long int const a,
long int const b )
186 return ( a < b ? b : a );
193 max(
unsigned short int const a,
unsigned short int const b )
195 return ( a < b ? b : a );
202 max(
unsigned int const a,
unsigned int const b )
204 return ( a < b ? b : a );
211 max(
unsigned long int const a,
unsigned long int const b )
213 return ( a < b ? b : a );
222 return ( a < b ? b : a );
229 max(
double const a,
double const b )
231 return ( a < b ? b : a );
238 max(
long double const a,
long double const b )
240 return ( a < b ? b : a );
249 template<
typename T >
254 return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) );
259 template<
typename T >
262 max(
T const &
a,
T const &
b,
T const & c,
T const & d )
269 template<
typename T >
272 max(
T const &
a,
T const &
b,
T const & c,
T const & d,
T const & e )
279 template<
typename T >
282 max(
T const &
a,
T const &
b,
T const & c,
T const & d,
T const & e,
T const &
f )
292 template<
typename T >
297 return ( x <
T( 0 ) ? -x : x );
302 template<
typename T >
312 template<
typename T >
322 template<
typename T >
327 return ( x >=
T( 0 ) ? +1 : -1 );
332 template<
typename X,
typename Y >
342 template<
typename R,
typename T,
bool >
356 template<
typename R,
typename T >
364 return R( x + (
sign( x ) *
T( 0.5 ) ) );
370 template<
typename R,
typename T >
380 template<
typename T >
385 return std::size_t( x >
T( 0 ) ? x + (
sign( x ) *
T( 0.5 ) ) : 0 );
390 template<
typename T >
400 template<
typename T >
405 return static_cast< int >( x + (
sign( x ) *
T( 0.5 ) ) );
410 template<
typename T >
415 return static_cast< int >( x + (
sign( x ) *
T( 0.5 ) ) );
420 template<
typename T >
425 return static_cast< short int >( x + (
sign( x ) *
T( 0.5 ) ) );
430 template<
typename T >
435 return static_cast< long int >( x + (
sign( x ) *
T( 0.5 ) ) );
440 template<
typename T,
bool >
448 return ( y !=
T( 0 ) ? x - (
T( static_cast< SSize >( x / y ) ) * y ) :
T( 0 ) );
456 template<
typename T >
464 return ( y !=
T( 0 ) ? x - ( ( x / y ) * y ) :
T( 0 ) );
472 template<
typename T >
484 mod(
float const & i,
float const & n )
487 return ( n == 0.0
f ? 0.0
f : std::fmod( i, n ) );
494 mod(
double const & i,
double const & n )
497 return ( n == 0.0 ? 0.0 : std::fmod( i, n ) );
504 mod(
long double const & i,
long double const & n )
507 return ( n == 0.0
l ? 0.0
l : std::fmod( i, n ) );
512 template<
typename T,
bool >
520 return ( y !=
T( 0 ) ? x - ( std::floor( x / y ) * y ) :
T( 0 ) );
526 template<
typename T >
534 return ( y !=
T( 0 ) ? x - (
T( std::floor( static_cast< long double >( x ) / y ) ) * y ) :
T( 0 ) );
540 template<
typename T >
550 template<
typename T,
bool >
561 T const x_over_y( x / y );
564 T const n_minus_x_over_y(
T( n ) - x_over_y );
565 if ( n_minus_x_over_y ==
T( 0.5 ) ) {
567 }
else if ( n_minus_x_over_y ==
T( -0.5 ) ) {
571 return ( x - ( n * y ) );
578 template<
typename T >
589 long double const x_over_y( static_cast< long double >( x ) / y );
592 long double const n_minus_x_over_y( static_cast< long double >( n ) - x_over_y );
593 if ( n_minus_x_over_y == 0.5
l ) {
595 }
else if ( n_minus_x_over_y == -0.5
l ) {
599 return ( x - ( n * y ) );
610 template<
typename T >
620 template<
typename T,
bool >
634 template<
typename T >
642 return ( y !=
T( 0 ) ? x - (
nearest_ssize( static_cast< long double >( x ) / y ) * y ) :
T( 0 ) );
651 template<
typename T >
661 template<
typename T,
typename S >
672 template<
typename T >
679 while ( lo >
T( 0 ) ) {
680 T const rem(
mod( hi, lo ) );
692 template<
typename T >
698 assert( r_tol >=
T( 0 ) );
699 assert( a_tol >=
T( 0 ) );
705 template<
typename T >
711 assert( r_tol >=
T( 0 ) );
712 assert( a_tol >=
T( 0 ) );
718 template<
typename T >
724 assert( r_tol >=
T( 0 ) );
725 assert( a_tol >=
T( 0 ) );
731 template<
typename T >
737 assert( r_tol >=
T( 0 ) );
738 assert( a_tol >=
T( 0 ) );
744 template<
typename T >
750 assert( r_tol >=
T( 0 ) );
751 assert( a_tol >=
T( 0 ) );
761 template<
typename T >
771 template<
typename T >
781 template<
typename T >
791 template<
typename T >
801 template<
typename T >
806 assert( pos >=
T( 0 ) );
807 return ( x | (
T( 1 ) << pos ) );
812 template<
typename T >
817 assert( pos >=
T( 0 ) );
818 return ( x & ~(
T( 1 ) << pos ) );
823 template<
typename T >
828 assert( pos >=
T( 0 ) );
829 return ( x & (
T( 1 ) << pos ) );
839 #endif // INCLUDED_ObjexxFCL_Fmath_HH
Fast remainder function selector class for non-integer types.
short int nsint(T const &x)
nsint( x ): Nearest short int
T bit_xor(T const &x, T const &y)
Bitwise Exclusive Or.
DimensionExpressionCube cube(Dimension const &dim)
cube( Dimension )
DimensionExpressionMin min(Dimension const &dim1, Dimension const &dim2)
min( Dimension, Dimension )
T gcd(T const &m, T const &n)
Greatest Common Divisor.
Mod function selector class for non-integer types.
Nearest function selector class for R non-integer or T integer.
FileVectorOptionKey const s
bool lt_tol(T const &x, T const &y, T const &r_tol, T const &a_tol)
Less than within specified relative and absolute tolerances?
bool gt_tol(T const &x, T const &y, T const &r_tol, T const &a_tol)
Greater than within specified relative and absolute tolerances?
int sign(T const &x)
sign( x )
std::size_t nearest_size(T const &x)
nearest_size( x ): Nearest std::size_t
static T mod(T const &x, T const &y)
static R nearest(T const &x)
R nearest(T const &x)
nearest< R >( x ): Nearest R
static T fast_remainder(T const &x, T const &y)
static T mod(T const &x, T const &y)
static T remainder(T const &x, T const &y)
T remainder(T const &x, T const &y)
Remainder of x with respect to division by y that is of smallest magnitude.
Remainder function selector class for non-integer types.
T bit_and(T const &x, T const &y)
Bitwise And.
static R nearest(T const &x)
T abs(T const &x)
std::abs( x ) == | x |
T bit_clr(T const &x, T const &pos)
Bit Value Set to 0.
long int nlint(T const &x)
nlint( x ): Nearest long int
int nint(T const &x)
nint( x ): Nearest int
SSize nearest_ssize(T const &x)
nearest_ssize( x ): Nearest SSize
bool ge_tol(T const &x, T const &y, T const &r_tol, T const &a_tol)
Greater than or equal within specified relative and absolute tolerances?
static T remainder(T const &x, T const &y)
T remainder_conversion(T const &t, S &s)
Remainder and result of conversion to a different type.
int nearest_int(T const &x)
nearest_int( x ): Nearest int
T mod(T const &x, T const &y)
x(mod y) computational modulo returning magnitude < | y | and sign of x
T bit_not(T const &x)
Bitwise Not.
DimensionExpressionMax max(Dimension const &dim1, Dimension const &dim2)
max( Dimension, Dimension )
T bit_or(T const &x, T const &y)
Bitwise Inclusive Or.
Modulo function selector class for non-integer types.
T modulo(T const &x, T const &y)
x(mod y) mathematical modulo returning magnitude < | y | and sign of y
static T modulo(T const &x, T const &y)
T bit_set(T const &x, T const &pos)
Bit Value Set to 1.
bool eq_tol(T const &x, T const &y, T const &r_tol, T const &a_tol)
Equal within specified relative and absolute tolerances?
T fast_remainder(T const &x, T const &y)
Remainder of x with respect to division by y that is of smallest magnitude.
static T modulo(T const &x, T const &y)
bool bit_test(T const &x, T const &pos)
Bit Value Test.
DimensionExpressionSquare square(Dimension const &dim)
square( Dimension )
bool le_tol(T const &x, T const &y, T const &r_tol, T const &a_tol)
Less than or equal within specified relative and absolute tolerances?
FileVectorOptionKey const l
static T fast_remainder(T const &x, T const &y)
FileVectorOptionKey const t