Changeset f3458a8 for src/libcfa/stdlib


Ignore:
Timestamp:
Jan 2, 2018, 10:39:57 AM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
8aa474a
Parents:
f64d9bc (diff), 93cdd5c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/stdlib

    rf64d9bc rf3458a8  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Oct 31 13:47:24 2017
    13 // Update Count     : 245
     12// Last Modified On : Mon Jan  1 17:35:43 2018
     13// Update Count     : 291
    1414//
    1515
    1616#pragma once
     17
     18//#define _XOPEN_SOURCE 600                                                             // posix_memalign, *rand48
     19#include <stdlib.h>                                                                             // strto*, *abs
    1720
    1821//---------------------------------------
     
    7780        //printf( "X8\n" );
    7881        T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );     // C malloc
    79     return (T *)memset( ptr, (int)fill, sizeof(T) );                    // initial with fill value
     82    return (T *)memset( ptr, (int)fill, sizeof(T) );    // initial with fill value
    8083} // alloc
    8184
     
    150153//---------------------------------------
    151154
    152 int ato( const char * ptr );
    153 unsigned int ato( const char * ptr );
    154 long int ato( const char * ptr );
    155 unsigned long int ato( const char * ptr );
    156 long long int ato( const char * ptr );
    157 unsigned long long int ato( const char * ptr );
    158 float ato( const char * ptr );
    159 double ato( const char * ptr );
    160 long double ato( const char * ptr );
    161 float _Complex ato( const char * ptr );
    162 double _Complex ato( const char * ptr );
    163 long double _Complex ato( const char * ptr );
    164 
    165 int strto( const char * sptr, char ** eptr, int base );
    166 unsigned int strto( const char * sptr, char ** eptr, int base );
    167 long int strto( const char * sptr, char ** eptr, int base );
    168 unsigned long int strto( const char * sptr, char ** eptr, int base );
    169 long long int strto( const char * sptr, char ** eptr, int base );
    170 unsigned long long int strto( const char * sptr, char ** eptr, int base );
    171 float strto( const char * sptr, char ** eptr );
    172 double strto( const char * sptr, char ** eptr );
    173 long double strto( const char * sptr, char ** eptr );
     155static inline int strto( const char * sptr, char ** eptr, int base ) { return (int)strtol( sptr, eptr, base ); }
     156static inline unsigned int strto( const char * sptr, char ** eptr, int base ) { return (unsigned int)strtoul( sptr, eptr, base ); }
     157static inline long int strto( const char * sptr, char ** eptr, int base ) { return strtol( sptr, eptr, base ); }
     158static inline unsigned long int strto( const char * sptr, char ** eptr, int base ) { return strtoul( sptr, eptr, base ); }
     159static inline long long int strto( const char * sptr, char ** eptr, int base ) { return strtoll( sptr, eptr, base ); }
     160static inline unsigned long long int strto( const char * sptr, char ** eptr, int base ) { return strtoull( sptr, eptr, base ); }
     161
     162static inline float strto( const char * sptr, char ** eptr ) { return strtof( sptr, eptr ); }
     163static inline double strto( const char * sptr, char ** eptr ) { return strtod( sptr, eptr ); }
     164static inline long double strto( const char * sptr, char ** eptr ) { return strtold( sptr, eptr ); }
     165
    174166float _Complex strto( const char * sptr, char ** eptr );
    175167double _Complex strto( const char * sptr, char ** eptr );
    176168long double _Complex strto( const char * sptr, char ** eptr );
    177169
    178 //---------------------------------------
    179 
    180 forall( otype T | { int ?<?( T, T ); } )
    181 T * bsearch( T key, const T * arr, size_t dim );
    182 
    183 forall( otype T | { int ?<?( T, T ); } )
    184 unsigned int bsearch( T key, const T * arr, size_t dim );
    185 
    186 
    187 forall( otype T | { int ?<?( T, T ); } )
    188 void qsort( const T * arr, size_t dim );
     170static inline int ato( const char * sptr ) {return (int)strtol( sptr, 0, 10 ); }
     171static inline unsigned int ato( const char * sptr ) { return (unsigned int)strtoul( sptr, 0, 10 ); }
     172static inline long int ato( const char * sptr ) { return strtol( sptr, 0, 10 ); }
     173static inline unsigned long int ato( const char * sptr ) { return strtoul( sptr, 0, 10 ); }
     174static inline long long int ato( const char * sptr ) { return strtoll( sptr, 0, 10 ); }
     175static inline unsigned long long int ato( const char * sptr ) { return strtoull( sptr, 0, 10 ); }
     176
     177static inline float ato( const char * sptr ) { return strtof( sptr, 0 ); }
     178static inline double ato( const char * sptr ) { return strtod( sptr, 0 ); }
     179static inline long double ato( const char * sptr ) { return strtold( sptr, 0 ); }
     180
     181static inline float _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
     182static inline double _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
     183static inline long double _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
     184
     185//---------------------------------------
     186
     187forall( otype E | { int ?<?( E, E ); } )
     188E * bsearch( E key, const E * vals, size_t dim );
     189
     190forall( otype E | { int ?<?( E, E ); } )
     191size_t bsearch( E key, const E * vals, size_t dim );
     192
     193forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
     194E * bsearch( K key, const E * vals, size_t dim );
     195
     196forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
     197size_t bsearch( K key, const E * vals, size_t dim );
     198
     199
     200forall( otype E | { int ?<?( E, E ); } )
     201E * bsearchl( E key, const E * vals, size_t dim );
     202
     203forall( otype E | { int ?<?( E, E ); } )
     204size_t bsearchl( E key, const E * vals, size_t dim );
     205
     206forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
     207E * bsearchl( K key, const E * vals, size_t dim );
     208
     209forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
     210size_t bsearchl( K key, const E * vals, size_t dim );
     211
     212
     213forall( otype E | { int ?<?( E, E ); } )
     214E * bsearchu( E key, const E * vals, size_t dim );
     215
     216forall( otype E | { int ?<?( E, E ); } )
     217size_t bsearchu( E key, const E * vals, size_t dim );
     218
     219forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
     220E * bsearchu( K key, const E * vals, size_t dim );
     221
     222forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
     223size_t bsearchu( K key, const E * vals, size_t dim );
     224
     225
     226forall( otype E | { int ?<?( E, E ); } )
     227void qsort( E * vals, size_t dim );
    189228
    190229//---------------------------------------
     
    198237//---------------------------------------
    199238
    200 unsigned char abs( signed char );
     239static inline unsigned char abs( signed char v ) { return abs( (int)v ); }
    201240extern "C" { int abs( int ); }                                                  // use default C routine for int
    202 unsigned long int abs( long int );
    203 unsigned long long int abs( long long int );
    204 float abs( float );
    205 double abs( double );
    206 long double abs( long double );
    207 float abs( float _Complex );
    208 double abs( double _Complex );
    209 long double abs( long double _Complex );
     241static inline unsigned long int abs( long int v ) { return labs( v ); }
     242static inline unsigned long long int abs( long long int v ) { return llabs( v ); }
     243
     244extern "C" {
     245double fabs( double );
     246float fabsf( float );
     247long double fabsl( long double );
     248} // extern "C"
     249static inline float abs( float x ) { return fabsf( x ); }
     250static inline double abs( double x ) { return fabs( x ); }
     251static inline long double abs( long double x ) { return fabsl( x ); }
     252
     253extern "C" {
     254double cabs( double _Complex );
     255float cabsf( float _Complex );
     256long double cabsl( long double _Complex );
     257} // extern "C"
     258static inline float abs( float _Complex x ) { return cabsf( x ); }
     259static inline double abs( double _Complex x ) { return cabs( x ); }
     260static inline long double abs( long double _Complex x ) { return cabsl( x ); }
     261
    210262forall( otype T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } )
    211263T abs( T );
     
    215267void random_seed( long int s );
    216268char random( void );
     269char random( char u );
    217270char random( char l, char u );
    218271int random( void );
     272int random( int u );
     273int random( int l, int u );
    219274unsigned int random( void );
    220275unsigned int random( unsigned int u );
    221276unsigned int random( unsigned int l, unsigned int u );
    222 //long int random( void );
     277extern "C" { long int random( void ); }
     278long int random( long int u );
     279long int random( long int l, long int u );
    223280unsigned long int random( void );
    224281unsigned long int random( unsigned long int u );
     
    233290
    234291forall( otype T | { int ?<?( T, T ); } )
    235 T min( T t1, T t2 );
     292static inline T min( T t1, T t2 ) { return t1 < t2 ? t1 : t2; }
    236293
    237294forall( otype T | { int ?>?( T, T ); } )
    238 T max( T t1, T t2 );
     295static inline T max( T t1, T t2 ) { return t1 > t2 ? t1 : t2; }
    239296
    240297forall( otype T | { T min( T, T ); T max( T, T ); } )
    241 T clamp( T value, T min_val, T max_val );
     298static inline T clamp( T value, T min_val, T max_val ) { return max( min_val, min( value, max_val ) ); }
    242299
    243300forall( otype T )
    244 void swap( T & t1, T & t2 );
     301static inline void swap( T & v1, T & v2 ) { T temp = v1; v1 = v2; v2 = temp; }
    245302
    246303// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.