Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/stdlib

    r54aba8d rcdbfab0  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan  2 12:21:04 2018
    13 // Update Count     : 292
     12// Last Modified On : Tue Oct 31 13:47:24 2017
     13// Update Count     : 245
    1414//
    1515
    1616#pragma once
    17 
    18 //#define _XOPEN_SOURCE 600                                                             // posix_memalign, *rand48
    19 #include <stdlib.h>                                                                             // strto*, *abs
    2017
    2118//---------------------------------------
     
    8077        //printf( "X8\n" );
    8178        T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );     // C malloc
    82     return (T *)memset( ptr, (int)fill, sizeof(T) );    // initial with fill value
     79    return (T *)memset( ptr, (int)fill, sizeof(T) );                    // initial with fill value
    8380} // alloc
    8481
     
    153150//---------------------------------------
    154151
    155 static inline int strto( const char * sptr, char ** eptr, int base ) { return (int)strtol( sptr, eptr, base ); }
    156 static inline unsigned int strto( const char * sptr, char ** eptr, int base ) { return (unsigned int)strtoul( sptr, eptr, base ); }
    157 static inline long int strto( const char * sptr, char ** eptr, int base ) { return strtol( sptr, eptr, base ); }
    158 static inline unsigned long int strto( const char * sptr, char ** eptr, int base ) { return strtoul( sptr, eptr, base ); }
    159 static inline long long int strto( const char * sptr, char ** eptr, int base ) { return strtoll( sptr, eptr, base ); }
    160 static inline unsigned long long int strto( const char * sptr, char ** eptr, int base ) { return strtoull( sptr, eptr, base ); }
    161 
    162 static inline float strto( const char * sptr, char ** eptr ) { return strtof( sptr, eptr ); }
    163 static inline double strto( const char * sptr, char ** eptr ) { return strtod( sptr, eptr ); }
    164 static inline long double strto( const char * sptr, char ** eptr ) { return strtold( sptr, eptr ); }
    165 
     152int ato( const char * ptr );
     153unsigned int ato( const char * ptr );
     154long int ato( const char * ptr );
     155unsigned long int ato( const char * ptr );
     156long long int ato( const char * ptr );
     157unsigned long long int ato( const char * ptr );
     158float ato( const char * ptr );
     159double ato( const char * ptr );
     160long double ato( const char * ptr );
     161float _Complex ato( const char * ptr );
     162double _Complex ato( const char * ptr );
     163long double _Complex ato( const char * ptr );
     164
     165int strto( const char * sptr, char ** eptr, int base );
     166unsigned int strto( const char * sptr, char ** eptr, int base );
     167long int strto( const char * sptr, char ** eptr, int base );
     168unsigned long int strto( const char * sptr, char ** eptr, int base );
     169long long int strto( const char * sptr, char ** eptr, int base );
     170unsigned long long int strto( const char * sptr, char ** eptr, int base );
     171float strto( const char * sptr, char ** eptr );
     172double strto( const char * sptr, char ** eptr );
     173long double strto( const char * sptr, char ** eptr );
    166174float _Complex strto( const char * sptr, char ** eptr );
    167175double _Complex strto( const char * sptr, char ** eptr );
    168176long double _Complex strto( const char * sptr, char ** eptr );
    169177
    170 static inline int ato( const char * sptr ) {return (int)strtol( sptr, 0, 10 ); }
    171 static inline unsigned int ato( const char * sptr ) { return (unsigned int)strtoul( sptr, 0, 10 ); }
    172 static inline long int ato( const char * sptr ) { return strtol( sptr, 0, 10 ); }
    173 static inline unsigned long int ato( const char * sptr ) { return strtoul( sptr, 0, 10 ); }
    174 static inline long long int ato( const char * sptr ) { return strtoll( sptr, 0, 10 ); }
    175 static inline unsigned long long int ato( const char * sptr ) { return strtoull( sptr, 0, 10 ); }
    176 
    177 static inline float ato( const char * sptr ) { return strtof( sptr, 0 ); }
    178 static inline double ato( const char * sptr ) { return strtod( sptr, 0 ); }
    179 static inline long double ato( const char * sptr ) { return strtold( sptr, 0 ); }
    180 
    181 static inline float _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
    182 static inline double _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
    183 static inline long double _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
    184 
    185 //---------------------------------------
    186 
    187 forall( otype E | { int ?<?( E, E ); } )
    188 E * bsearch( E key, const E * vals, size_t dim );
    189 
    190 forall( otype E | { int ?<?( E, E ); } )
    191 size_t bsearch( E key, const E * vals, size_t dim );
    192 
    193 forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
    194 E * bsearch( K key, const E * vals, size_t dim );
    195 
    196 forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
    197 size_t bsearch( K key, const E * vals, size_t dim );
    198 
    199 
    200 forall( otype E | { int ?<?( E, E ); } )
    201 E * bsearchl( E key, const E * vals, size_t dim );
    202 
    203 forall( otype E | { int ?<?( E, E ); } )
    204 size_t bsearchl( E key, const E * vals, size_t dim );
    205 
    206 forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
    207 E * bsearchl( K key, const E * vals, size_t dim );
    208 
    209 forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
    210 size_t bsearchl( K key, const E * vals, size_t dim );
    211 
    212 
    213 forall( otype E | { int ?<?( E, E ); } )
    214 E * bsearchu( E key, const E * vals, size_t dim );
    215 
    216 forall( otype E | { int ?<?( E, E ); } )
    217 size_t bsearchu( E key, const E * vals, size_t dim );
    218 
    219 forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
    220 E * bsearchu( K key, const E * vals, size_t dim );
    221 
    222 forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
    223 size_t bsearchu( K key, const E * vals, size_t dim );
    224 
    225 
    226 forall( otype E | { int ?<?( E, E ); } )
    227 void qsort( E * vals, size_t dim );
     178//---------------------------------------
     179
     180forall( otype T | { int ?<?( T, T ); } )
     181T * bsearch( T key, const T * arr, size_t dim );
     182
     183forall( otype T | { int ?<?( T, T ); } )
     184unsigned int bsearch( T key, const T * arr, size_t dim );
     185
     186
     187forall( otype T | { int ?<?( T, T ); } )
     188void qsort( const T * arr, size_t dim );
    228189
    229190//---------------------------------------
     
    237198//---------------------------------------
    238199
    239 static inline unsigned char abs( signed char v ) { return abs( (int)v ); }
     200unsigned char abs( signed char );
    240201extern "C" { int abs( int ); }                                                  // use default C routine for int
    241 static inline unsigned long int abs( long int v ) { return labs( v ); }
    242 static inline unsigned long long int abs( long long int v ) { return llabs( v ); }
    243 
    244 extern "C" {
    245 double fabs( double );
    246 float fabsf( float );
    247 long double fabsl( long double );
    248 } // extern "C"
    249 static inline float abs( float x ) { return fabsf( x ); }
    250 static inline double abs( double x ) { return fabs( x ); }
    251 static inline long double abs( long double x ) { return fabsl( x ); }
    252 
    253 extern "C" {
    254 double cabs( double _Complex );
    255 float cabsf( float _Complex );
    256 long double cabsl( long double _Complex );
    257 } // extern "C"
    258 static inline float abs( float _Complex x ) { return cabsf( x ); }
    259 static inline double abs( double _Complex x ) { return cabs( x ); }
    260 static inline long double abs( long double _Complex x ) { return cabsl( x ); }
    261 
     202unsigned long int abs( long int );
     203unsigned long long int abs( long long int );
     204float abs( float );
     205double abs( double );
     206long double abs( long double );
     207float abs( float _Complex );
     208double abs( double _Complex );
     209long double abs( long double _Complex );
    262210forall( otype T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } )
    263211T abs( T );
     
    265213//---------------------------------------
    266214
    267 extern "C" { void srandom( unsigned int seed ); }               // override C version
     215void random_seed( long int s );
    268216char random( void );
    269 char random( char u );
    270217char random( char l, char u );
    271218int random( void );
    272 int random( int u );
    273 int random( int l, int u );
    274219unsigned int random( void );
    275220unsigned int random( unsigned int u );
    276221unsigned int random( unsigned int l, unsigned int u );
    277 extern "C" { long int random( void ); }                                 // override C version
    278 long int random( long int u );
    279 long int random( long int l, long int u );
     222//long int random( void );
    280223unsigned long int random( void );
    281224unsigned long int random( unsigned long int u );
     
    290233
    291234forall( otype T | { int ?<?( T, T ); } )
    292 static inline T min( T t1, T t2 ) { return t1 < t2 ? t1 : t2; }
     235T min( T t1, T t2 );
    293236
    294237forall( otype T | { int ?>?( T, T ); } )
    295 static inline T max( T t1, T t2 ) { return t1 > t2 ? t1 : t2; }
     238T max( T t1, T t2 );
    296239
    297240forall( otype T | { T min( T, T ); T max( T, T ); } )
    298 static inline T clamp( T value, T min_val, T max_val ) { return max( min_val, min( value, max_val ) ); }
     241T clamp( T value, T min_val, T max_val );
    299242
    300243forall( otype T )
    301 static inline void swap( T & v1, T & v2 ) { T temp = v1; v1 = v2; v2 = temp; }
     244void swap( T & t1, T & t2 );
    302245
    303246// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.