source: libcfa/src/common.hfa @ 341e252

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 341e252 was 6553828, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

add specialized char, intptr_t, uintptr_t definitions for min and max

  • Property mode set to 100644
File size: 2.9 KB
Line 
1//
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.
6//
7// common --
8//
9// Author           : Peter A. Buhr
10// Created On       : Wed Jul 11 17:54:36 2018
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sat Aug 15 08:51:29 2020
13// Update Count     : 14
14//
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 );
23forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
24[ T, T ] div( T num, T demon );
25
26//---------------------------------------
27
28extern "C" {
29        int abs( int );                                                                         // stdlib.h
30        long int labs( long int );
31        long long int llabs( long long int );
32} // extern "C"
33
34static inline {
35        unsigned char abs( signed char v ) { return abs( (int)v ); }
36        // use default C routine for int
37        unsigned long int abs( long int v ) { return labs( v ); }
38        unsigned long long int abs( long long int v ) { return llabs( v ); }
39} // distribution
40
41extern "C" {
42        double fabs( double );                                                          // math.h
43        float fabsf( float );
44        long double fabsl( long double );
45} // extern "C"
46static inline {
47        float abs( float x ) { return fabsf( x ); }
48        double abs( double x ) { return fabs( x ); }
49        long double abs( long double x ) { return fabsl( x ); }
50} // distribution
51
52extern "C" {
53        double cabs( double _Complex );                                         // complex.h
54        float cabsf( float _Complex );
55        long double cabsl( long double _Complex );
56} // extern "C"
57static inline {
58        float abs( float _Complex x ) { return cabsf( x ); }
59        double abs( double _Complex x ) { return cabs( x ); }
60        long double abs( long double _Complex x ) { return cabsl( x ); }
61} // distribution
62
63forall( otype T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } )
64T abs( T );
65
66//---------------------------------------
67
68static inline {
69        char min( char t1, char t2 ) { return t1 < t2 ? t1 : t2; } // optimization
70        intptr_t min( intptr_t t1, intptr_t t2 ) { return t1 < t2 ? t1 : t2; } // optimization
71        uintptr_t min( uintptr_t t1, uintptr_t t2 ) { return t1 < t2 ? t1 : t2; } // optimization
72        forall( otype T | { int ?<?( T, T ); } )
73        T min( T t1, T t2 ) { return t1 < t2 ? t1 : t2; }
74
75        char max( char t1, char t2 ) { return t1 > t2 ? t1 : t2; } // optimization
76        intptr_t max( intptr_t t1, intptr_t t2 ) { return t1 > t2 ? t1 : t2; } // optimization
77        uintptr_t max( uintptr_t t1, uintptr_t t2 ) { return t1 > t2 ? t1 : t2; } // optimization
78        forall( otype T | { int ?>?( T, T ); } )
79        T max( T t1, T t2 ) { return t1 > t2 ? t1 : t2; }
80
81        forall( otype T | { T min( T, T ); T max( T, T ); } )
82        T clamp( T value, T min_val, T max_val ) { return max( min_val, min( value, max_val ) ); }
83
84        forall( otype T )
85        void swap( T & v1, T & v2 ) { T temp = v1; v1 = v2; v2 = temp; }
86} // distribution
87
88// Local Variables: //
89// mode: c //
90// tab-width: 4 //
91// End: //
Note: See TracBrowser for help on using the repository browser.