source: libcfa/src/common.hfa @ a254fa56

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since a254fa56 was 73abe95, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Replace extension-less headers with .hfa

  • Property mode set to 100644
File size: 2.4 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 : Thu Jul 12 08:02:18 2018
13// Update Count     : 5
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        forall( otype T | { int ?<?( T, T ); } )
70        T min( T t1, T t2 ) { return t1 < t2 ? t1 : t2; }
71
72        forall( otype T | { int ?>?( T, T ); } )
73        T max( T t1, T t2 ) { return t1 > t2 ? t1 : t2; }
74
75        forall( otype T | { T min( T, T ); T max( T, T ); } )
76        T clamp( T value, T min_val, T max_val ) { return max( min_val, min( value, max_val ) ); }
77
78        forall( otype T )
79        void swap( T & v1, T & v2 ) { T temp = v1; v1 = v2; v2 = temp; }
80} // distribution
81
82// Local Variables: //
83// mode: c //
84// tab-width: 4 //
85// End: //
Note: See TracBrowser for help on using the repository browser.