[91a72ef] | 1 | // |
---|
[0fc52b6] | 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
[91a72ef] | 6 | // |
---|
| 7 | // common.hfa -- |
---|
| 8 | // |
---|
[0fc52b6] | 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Wed Jul 11 17:54:36 2018 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[95bda0a] | 12 | // Last Modified On : Sat Oct 8 08:32:57 2022 |
---|
| 13 | // Update Count : 23 |
---|
[91a72ef] | 14 | // |
---|
[0fc52b6] | 15 | |
---|
| 16 | #pragma once |
---|
| 17 | |
---|
| 18 | //--------------------------------------- |
---|
| 19 | |
---|
| 20 | [ int, int ] div( int num, int denom ); |
---|
| 21 | [ long int, long int ] div( long int num, long int denom ); |
---|
| 22 | [ long long int, long long int ] div( long long int num, long long int denom ); |
---|
[fd54fef] | 23 | forall( T | { T ?/?( T, T ); T ?%?( T, T ); } ) |
---|
[0fc52b6] | 24 | [ T, T ] div( T num, T demon ); |
---|
| 25 | |
---|
| 26 | //--------------------------------------- |
---|
| 27 | |
---|
| 28 | extern "C" { |
---|
| 29 | int abs( int ); // stdlib.h |
---|
| 30 | long int labs( long int ); |
---|
| 31 | long long int llabs( long long int ); |
---|
| 32 | } // extern "C" |
---|
[95bda0a] | 33 | static inline __attribute__((always_inline)) { |
---|
[24d6572] | 34 | unsigned char abs( signed char v ) { return (int)abs( (int)v ); } |
---|
[0fc52b6] | 35 | // use default C routine for int |
---|
| 36 | unsigned long int abs( long int v ) { return labs( v ); } |
---|
| 37 | unsigned long long int abs( long long int v ) { return llabs( v ); } |
---|
| 38 | } // distribution |
---|
| 39 | |
---|
| 40 | extern "C" { |
---|
| 41 | double fabs( double ); // math.h |
---|
| 42 | float fabsf( float ); |
---|
| 43 | long double fabsl( long double ); |
---|
| 44 | } // extern "C" |
---|
[95bda0a] | 45 | static inline __attribute__((always_inline)) { |
---|
[0fc52b6] | 46 | float abs( float x ) { return fabsf( x ); } |
---|
| 47 | double abs( double x ) { return fabs( x ); } |
---|
| 48 | long double abs( long double x ) { return fabsl( x ); } |
---|
| 49 | } // distribution |
---|
| 50 | |
---|
| 51 | extern "C" { |
---|
| 52 | double cabs( double _Complex ); // complex.h |
---|
| 53 | float cabsf( float _Complex ); |
---|
| 54 | long double cabsl( long double _Complex ); |
---|
| 55 | } // extern "C" |
---|
[95bda0a] | 56 | static inline __attribute__((always_inline)) { |
---|
[0fc52b6] | 57 | float abs( float _Complex x ) { return cabsf( x ); } |
---|
| 58 | double abs( double _Complex x ) { return cabs( x ); } |
---|
| 59 | long double abs( long double _Complex x ) { return cabsl( x ); } |
---|
| 60 | } // distribution |
---|
| 61 | |
---|
[fd54fef] | 62 | forall( T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } ) |
---|
[0fc52b6] | 63 | T abs( T ); |
---|
| 64 | |
---|
| 65 | //--------------------------------------- |
---|
| 66 | |
---|
[95bda0a] | 67 | static inline __attribute__((always_inline)) { |
---|
[4026d1be] | 68 | char min( char v1, char v2 ) { return v1 < v2 ? v1 : v2; } // optimization |
---|
| 69 | int min( int v1, int v2 ) { return v1 < v2 ? v1 : v2; } |
---|
| 70 | unsigned int min( unsigned int v1, unsigned int v2 ) { return v1 < v2 ? v1 : v2; } |
---|
| 71 | long int min( long int v1, long int v2 ) { return v1 < v2 ? v1 : v2; } |
---|
[24d6572] | 72 | unsigned long int min( unsigned long int v1, unsigned long int v2 ) { return v1 < v2 ? v1 : v2; } |
---|
[4026d1be] | 73 | long long int min( long long int v1, long long int v2 ) { return v1 < v2 ? v1 : v2; } |
---|
[24d6572] | 74 | unsigned long long int min( unsigned long long int v1, unsigned long long int v2 ) { return v1 < v2 ? v1 : v2; } |
---|
[95bda0a] | 75 | forall( T | { int ?<?( T, T ); } ) // generic |
---|
[4026d1be] | 76 | T min( T v1, T v2 ) { return v1 < v2 ? v1 : v2; } |
---|
[0fc52b6] | 77 | |
---|
[4026d1be] | 78 | char max( char v1, char v2 ) { return v1 > v2 ? v1 : v2; } // optimization |
---|
| 79 | int max( int v1, int v2 ) { return v1 > v2 ? v1 : v2; } |
---|
| 80 | unsigned int max( unsigned int v1, unsigned int v2 ) { return v1 > v2 ? v1 : v2; } |
---|
| 81 | long int max( long int v1, long int v2 ) { return v1 > v2 ? v1 : v2; } |
---|
| 82 | unsigned long int max( unsigned long int v1, unsigned long int v2 ) { return v1 > v2 ? v1 : v2; } |
---|
| 83 | long long int max( long long int v1, long long int v2 ) { return v1 > v2 ? v1 : v2; } |
---|
| 84 | unsigned long long int max( unsigned long long int v1, unsigned long long int v2 ) { return v1 > v2 ? v1 : v2; } |
---|
[95bda0a] | 85 | forall( T | { int ?>?( T, T ); } ) // generic |
---|
[4026d1be] | 86 | T max( T v1, T v2 ) { return v1 > v2 ? v1 : v2; } |
---|
[0fc52b6] | 87 | |
---|
[fd54fef] | 88 | forall( T | { T min( T, T ); T max( T, T ); } ) |
---|
[0fc52b6] | 89 | T clamp( T value, T min_val, T max_val ) { return max( min_val, min( value, max_val ) ); } |
---|
| 90 | |
---|
[fd54fef] | 91 | forall( T ) |
---|
[0fc52b6] | 92 | void swap( T & v1, T & v2 ) { T temp = v1; v1 = v2; v2 = temp; } |
---|
| 93 | } // distribution |
---|
| 94 | |
---|
| 95 | // Local Variables: // |
---|
| 96 | // mode: c // |
---|
| 97 | // tab-width: 4 // |
---|
| 98 | // End: // |
---|