source: src/libcfa/algorithm.c@ 98735ef

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since 98735ef was b4cd03b7, checked in by Rob Schluntz <rschlunt@…>, 10 years ago

fix many warnings from gcc by adding appropriate casts to adapter parameters

  • 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 : Rob Schluntz
12// Last Modified On : Thu Feb 04 17:19:12 2016
13// Update Count : 54
14//
15
16#include "algorithm"
17
18forall( type T | { int ?<?( const T, const T ); } )
19T min( const T t1, const T t2 ) {
20 return t1 < t2 ? t1 : t2;
21} // min
22
23forall( type T | { int ?>?( const T, const 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.