source: src/libcfa/algorithm.c @ b10c9959

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since b10c9959 was 5721a6d, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

correctly set type for complex constants, consolidate function name tables, add offsetof, refactor printing complex constants to use basic types

  • Property mode set to 100644
File size: 2.3 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// algorithm.c --
8//
9// Author           : Peter A. Buhr
10// Created On       : Thu Jan 28 17:10:29 2016
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Mon Feb  1 13:42:05 2016
13// Update Count     : 52
14//
15
16#include "algorithm"
17
18forall( type T | { int ?<?( T, T ); } )
19T min( const T t1, const T t2 ) {
20        return t1 < t2 ? t1 : t2;
21} // min
22
23forall( type T | { int ?>?( T, T ); } )
24T max( const T t1, const T t2 ) {
25        return t1 > t2 ? t1 : t2;
26} // max
27
28//---------------------------------------
29
30forall( type T )
31void swap( T * t1, T * t2 ) {
32        T temp = *t1;
33        *t1 = *t2;
34        *t2 = temp;
35} // swap
36
37//---------------------------------------
38
39extern "C" {
40#define _XOPEN_SOURCE                                                                   // required to access "rand48" routines
41#include <stdlib.h>                                                                             // abs, labs, llabs
42#include <math.h>                                                                               // fabsf, fabs, fabsl
43#include <complex.h>                                                                    // cabsf, cabs, cabsl
44#undef I                                                                                                // free name
45} // extern
46
47char abs( char v ) { return abs( (int)v ); }
48long int abs( long int v ) { return labs( v ); }
49long long int abs( long long int v ) { return llabs( v ); }
50float abs( float v ) { return fabsf( v ); }
51double abs( double v ) { return fabs( v ); }
52long double abs( long double v ) { return fabsl( v ); }
53float _Complex abs( float _Complex v ) { return cabsf( v ); }
54double _Complex abs( double _Complex v ) { return cabs( v ); }
55long double _Complex abs( long double _Complex v ) { return cabsl( v ); }
56
57//---------------------------------------
58
59void randseed( long int s ) { srand48( s ); }
60char random() { return lrand48(); }
61int random() { return mrand48(); }
62unsigned int random() { return lrand48(); }
63long int random() { return mrand48(); }
64unsigned long int random() { return lrand48(); }
65float random() { return (float)drand48(); }                             // otherwise float uses lrand48
66double random() { return drand48(); }
67float _Complex random() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
68double _Complex random() { return drand48() + (double _Complex)(drand48() * _Complex_I); }
69long double _Complex random() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
70
71// Local Variables: //
72// tab-width: 4 //
73// End: //
Note: See TracBrowser for help on using the repository browser.