Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/stdlib

    r57fc7d8 rbbe1a87  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul  5 07:41:03 2018
    13 // Update Count     : 332
     12// Last Modified On : Tue Jul  3 08:17:28 2018
     13// Update Count     : 324
    1414//
    1515
     
    1818#include <stdlib.h>                                                                             // allocation, strto*, *abs
    1919extern "C" {
    20         void * memalign( size_t align, size_t size );           // malloc.h
    21         void * memset( void * dest, int c, size_t size );       // string.h
    22         void * memcpy( void * dest, const void * src, size_t size ); // string.h
     20        void * memalign( size_t align, size_t size );
     21        void * aligned_alloc( size_t align, size_t size );
     22        void * memset( void * dest, int c, size_t size );
    2323} // extern "C"
    2424
     
    140140        } // memset
    141141
     142        extern "C" { void * memcpy( void * dest, const void * src, size_t size ); } // use default C routine for void *
     143
    142144        T * memcpy( T * dest, const T * src ) {
    143145                //printf( "X18\n" );
     
    172174//---------------------------------------
    173175
    174 static inline {
    175         int strto( const char * sptr, char ** eptr, int base ) { return (int)strtol( sptr, eptr, base ); }
    176         unsigned int strto( const char * sptr, char ** eptr, int base ) { return (unsigned int)strtoul( sptr, eptr, base ); }
    177         long int strto( const char * sptr, char ** eptr, int base ) { return strtol( sptr, eptr, base ); }
    178         unsigned long int strto( const char * sptr, char ** eptr, int base ) { return strtoul( sptr, eptr, base ); }
    179         long long int strto( const char * sptr, char ** eptr, int base ) { return strtoll( sptr, eptr, base ); }
    180         unsigned long long int strto( const char * sptr, char ** eptr, int base ) { return strtoull( sptr, eptr, base ); }
    181 
    182         float strto( const char * sptr, char ** eptr ) { return strtof( sptr, eptr ); }
    183         double strto( const char * sptr, char ** eptr ) { return strtod( sptr, eptr ); }
    184         long double strto( const char * sptr, char ** eptr ) { return strtold( sptr, eptr ); }
    185 } // distribution
     176static inline int strto( const char * sptr, char ** eptr, int base ) { return (int)strtol( sptr, eptr, base ); }
     177static inline unsigned int strto( const char * sptr, char ** eptr, int base ) { return (unsigned int)strtoul( sptr, eptr, base ); }
     178static inline long int strto( const char * sptr, char ** eptr, int base ) { return strtol( sptr, eptr, base ); }
     179static inline unsigned long int strto( const char * sptr, char ** eptr, int base ) { return strtoul( sptr, eptr, base ); }
     180static inline long long int strto( const char * sptr, char ** eptr, int base ) { return strtoll( sptr, eptr, base ); }
     181static inline unsigned long long int strto( const char * sptr, char ** eptr, int base ) { return strtoull( sptr, eptr, base ); }
     182
     183static inline float strto( const char * sptr, char ** eptr ) { return strtof( sptr, eptr ); }
     184static inline double strto( const char * sptr, char ** eptr ) { return strtod( sptr, eptr ); }
     185static inline long double strto( const char * sptr, char ** eptr ) { return strtold( sptr, eptr ); }
    186186
    187187float _Complex strto( const char * sptr, char ** eptr );
     
    189189long double _Complex strto( const char * sptr, char ** eptr );
    190190
    191 static inline {
    192         int ato( const char * sptr ) {return (int)strtol( sptr, 0, 10 ); }
    193         unsigned int ato( const char * sptr ) { return (unsigned int)strtoul( sptr, 0, 10 ); }
    194         long int ato( const char * sptr ) { return strtol( sptr, 0, 10 ); }
    195         unsigned long int ato( const char * sptr ) { return strtoul( sptr, 0, 10 ); }
    196         long long int ato( const char * sptr ) { return strtoll( sptr, 0, 10 ); }
    197         unsigned long long int ato( const char * sptr ) { return strtoull( sptr, 0, 10 ); }
    198 
    199         float ato( const char * sptr ) { return strtof( sptr, 0 ); }
    200         double ato( const char * sptr ) { return strtod( sptr, 0 ); }
    201         long double ato( const char * sptr ) { return strtold( sptr, 0 ); }
    202 
    203         float _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
    204         double _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
    205         long double _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
    206 } // distribution
     191static inline int ato( const char * sptr ) {return (int)strtol( sptr, 0, 10 ); }
     192static inline unsigned int ato( const char * sptr ) { return (unsigned int)strtoul( sptr, 0, 10 ); }
     193static inline long int ato( const char * sptr ) { return strtol( sptr, 0, 10 ); }
     194static inline unsigned long int ato( const char * sptr ) { return strtoul( sptr, 0, 10 ); }
     195static inline long long int ato( const char * sptr ) { return strtoll( sptr, 0, 10 ); }
     196static inline unsigned long long int ato( const char * sptr ) { return strtoull( sptr, 0, 10 ); }
     197
     198static inline float ato( const char * sptr ) { return strtof( sptr, 0 ); }
     199static inline double ato( const char * sptr ) { return strtod( sptr, 0 ); }
     200static inline long double ato( const char * sptr ) { return strtold( sptr, 0 ); }
     201
     202static inline float _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
     203static inline double _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
     204static inline long double _Complex ato( const char * sptr ) { return strto( sptr, NULL ); }
    207205
    208206//---------------------------------------
     
    238236//---------------------------------------
    239237
     238static inline unsigned char abs( signed char v ) { return abs( (int)v ); }
    240239extern "C" { int abs( int ); }                                                  // use default C routine for int
    241 static inline {
    242         unsigned char abs( signed char v ) { return abs( (int)v ); }
    243         unsigned long int abs( long int v ) { return labs( v ); }
    244         unsigned long long int abs( long long int v ) { return llabs( v ); }
    245 } // distribution
    246 
    247 extern "C" {                                                                                    // use default C routine for int
    248         double fabs( double );
    249         float fabsf( float );
    250         long double fabsl( long double );
     240static inline unsigned long int abs( long int v ) { return labs( v ); }
     241static inline unsigned long long int abs( long long int v ) { return llabs( v ); }
     242
     243extern "C" {
     244double fabs( double );
     245float fabsf( float );
     246long double fabsl( long double );
    251247} // extern "C"
    252 static inline {
    253         float abs( float x ) { return fabsf( x ); }
    254         double abs( double x ) { return fabs( x ); }
    255         long double abs( long double x ) { return fabsl( x ); }
    256 } // distribution
    257 
    258 extern "C" {                                                                                    // use default C routine for int
    259         double cabs( double _Complex );
    260         float cabsf( float _Complex );
    261         long double cabsl( long double _Complex );
     248static inline float abs( float x ) { return fabsf( x ); }
     249static inline double abs( double x ) { return fabs( x ); }
     250static inline long double abs( long double x ) { return fabsl( x ); }
     251
     252extern "C" {
     253double cabs( double _Complex );
     254float cabsf( float _Complex );
     255long double cabsl( long double _Complex );
    262256} // extern "C"
    263 static inline {
    264         float abs( float _Complex x ) { return cabsf( x ); }
    265         double abs( double _Complex x ) { return cabs( x ); }
    266         long double abs( long double _Complex x ) { return cabsl( x ); }
    267 } // distribution
     257static inline float abs( float _Complex x ) { return cabsf( x ); }
     258static inline double abs( double _Complex x ) { return cabs( x ); }
     259static inline long double abs( long double _Complex x ) { return cabsl( x ); }
    268260
    269261forall( otype T | { void ?{}( T &, zero_t ); int ?<?( T, T ); T -?( T ); } )
     
    303295//---------------------------------------
    304296
    305 static inline {
    306         forall( otype T | { int ?<?( T, T ); } )
    307         T min( T t1, T t2 ) { return t1 < t2 ? t1 : t2; }
    308 
    309         forall( otype T | { int ?>?( T, T ); } )
    310         T max( T t1, T t2 ) { return t1 > t2 ? t1 : t2; }
    311 
    312         forall( otype T | { T min( T, T ); T max( T, T ); } )
    313         T clamp( T value, T min_val, T max_val ) { return max( min_val, min( value, max_val ) ); }
    314 
    315         forall( otype T )
    316         void swap( T & v1, T & v2 ) { T temp = v1; v1 = v2; v2 = temp; }
    317 } // distribution
     297forall( otype T | { int ?<?( T, T ); } )
     298static inline T min( T t1, T t2 ) { return t1 < t2 ? t1 : t2; }
     299
     300forall( otype T | { int ?>?( T, T ); } )
     301static inline T max( T t1, T t2 ) { return t1 > t2 ? t1 : t2; }
     302
     303forall( otype T | { T min( T, T ); T max( T, T ); } )
     304static inline T clamp( T value, T min_val, T max_val ) { return max( min_val, min( value, max_val ) ); }
     305
     306forall( otype T )
     307static inline void swap( T & v1, T & v2 ) { T temp = v1; v1 = v2; v2 = temp; }
    318308
    319309// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.