Changes in src/libcfa/stdlib.c [8bc4ef8:45161b4d]
- File:
-
- 1 edited
-
src/libcfa/stdlib.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/stdlib.c
r8bc4ef8 r45161b4d 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Apr 28 07:54:21201613 // Update Count : 1 6612 // Last Modified On : Wed Apr 13 14:49:58 2016 13 // Update Count : 155 14 14 // 15 15 … … 24 24 #include <malloc.h> // malloc_usable_size 25 25 #include <math.h> // fabsf, fabs, fabsl 26 #include <complex.h> // _Complex_I 26 #include <complex.h> // _Complex_I, cabsf, cabs, cabsl 27 27 } // extern "C" 28 28 … … 34 34 //printf( "malloc3\n" ); 35 35 T * ptr = (T *)malloc( sizeof(T) ); 36 return memset( ptr , (int)fill, sizeof(T));36 return memset( ptr ); 37 37 } // malloc 38 38 … … 78 78 } // posix_memalign 79 79 80 forall( otype T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill 81 //printf( "memset1\n" ); 82 return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) ); 83 } // memset 84 forall( otype T ) T * memset( T * ptr ) { // remove when default value available 85 //printf( "memset2\n" ); 86 return (T *)memset( ptr, 0, malloc_usable_size( ptr ) ); 87 } // memset 88 80 89 //--------------------------------------- 81 90 82 91 int ato( const char * ptr ) { 83 92 int i; 84 if ( sscanf( ptr, "%d", &i ) == EOF ) {} 93 if ( sscanf( ptr, "%d", &i ) == EOF ) {} // check return code 85 94 return i; 86 95 } 87 96 unsigned int ato( const char * ptr ) { 88 97 unsigned int ui; 89 if ( sscanf( ptr, "%u", &ui ) == EOF ) {} 98 if ( sscanf( ptr, "%u", &ui ) == EOF ) {} // check return code 90 99 return ui; 91 100 } 92 101 long int ato( const char * ptr ) { 93 102 long int li; 94 if ( sscanf( ptr, "%ld", &li ) == EOF ) {} 103 if ( sscanf( ptr, "%ld", &li ) == EOF ) {} // check return code 95 104 return li; 96 105 } 97 106 unsigned long int ato( const char * ptr ) { 98 107 unsigned long int uli; 99 if ( sscanf( ptr, "%lu", &uli ) == EOF ) {} 108 if ( sscanf( ptr, "%lu", &uli ) == EOF ) {} // check return code 100 109 return uli; 101 110 } 102 111 long long int ato( const char * ptr ) { 103 112 long long int lli; 104 if ( sscanf( ptr, "%lld", &lli ) == EOF ) {} 113 if ( sscanf( ptr, "%lld", &lli ) == EOF ) {} // check return code 105 114 return lli; 106 115 } 107 116 unsigned long long int ato( const char * ptr ) { 108 117 unsigned long long int ulli; 109 if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {} 118 if ( sscanf( ptr, "%llu", &ulli ) == EOF ) {} // check return code 110 119 return ulli; 111 120 } … … 113 122 float ato( const char * ptr ) { 114 123 float f; 115 if ( sscanf( ptr, "%f", &f ) == EOF ) {} 124 if ( sscanf( ptr, "%f", &f ) == EOF ) {} // check return code 116 125 return f; 117 126 } 118 127 double ato( const char * ptr ) { 119 128 double d; 120 if ( sscanf( ptr, "%lf", &d ) == EOF ) {} 129 if ( sscanf( ptr, "%lf", &d ) == EOF ) {} // check return code 121 130 return d; 122 131 } 123 132 long double ato( const char * ptr ) { 124 133 long double ld; 125 if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {} 134 if ( sscanf( ptr, "%Lf", &ld ) == EOF ) {} // check return code 126 135 return ld; 127 136 } … … 129 138 float _Complex ato( const char * ptr ) { 130 139 float re, im; 131 if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {} 140 if ( sscanf( ptr, "%g%gi", &re, &im ) == EOF ) {} // check return code 132 141 return re + im * _Complex_I; 133 142 } 134 143 double _Complex ato( const char * ptr ) { 135 144 double re, im; 136 if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} 145 if ( sscanf( ptr, "%lf%lfi", &re, &im ) == EOF ) {} // check return code 137 146 return re + im * _Complex_I; 138 147 } 139 148 long double _Complex ato( const char * ptr ) { 140 149 long double re, im; 141 if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {} 150 if ( sscanf( ptr, "%Lf%Lfi", &re, &im ) == EOF ) {} // check return code 142 151 return re + im * _Complex_I; 143 152 } … … 213 222 //--------------------------------------- 214 223 215 //forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )216 // [ T, T ] div( T t1, T t2 ) { return [ t1 / t2, t1 % t2 ];}224 forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } ) 225 [ T, T ] div( T t1, T t2 ) { /* return [ t1 / t2, t1 % t2 ]; */ } 217 226 218 227 //--------------------------------------- … … 221 230 long int abs( long int v ) { return labs( v ); } 222 231 long long int abs( long long int v ) { return llabs( v ); } 223 float abs( float x ) { return fabsf( x ); } 224 double abs( double x ) { return fabs( x ); } 225 long double abs( long double x ) { return fabsl( x ); } 226 float abs( float _Complex x ) { return cabsf( x ); } 227 double abs( double _Complex x ) { return cabs( x ); } 228 long double abs( long double _Complex x ) { return cabsl( x ); } 232 float abs( float v ) { return fabsf( v ); } 233 double abs( double v ) { return fabs( v ); } 234 long double abs( long double v ) { return fabsl( v ); } 235 float _Complex abs( float _Complex v ) { return cabsf( v ); } 236 double _Complex abs( double _Complex v ) { return cabs( v ); } 237 long double _Complex abs( long double _Complex v ) { return cabsl( v ); } 238 239 //--------------------------------------- 240 241 float floor( float v ) { return floorf( v ); } 242 long double floor( long double v ) { return floorl( v ); } 243 244 float ceil( float v ) { return ceilf( v ); } 245 long double ceil( long double v ) { return ceill( v ); } 229 246 230 247 //---------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.