Changeset 0438091
 Timestamp:
 Mar 22, 2016, 10:39:34 PM (8 years ago)
 Branches:
 ADT, aaronthesis, armeh, astexperimental, cleanupdtors, ctor, deferred_resn, demangler, enum, forallpointerdecay, gc_noraii, jacob/cs343translation, jenkinssandbox, master, memory, newast, newastuniqueexpr, newenv, no_list, persistentindexer, pthreademulation, qualifiedEnum, resolvnew, string, with_gc
 Children:
 6a57da5
 Parents:
 94980502
 Location:
 src
 Files:

 4 edited
Legend:
 Unmodified
 Added
 Removed

src/examples/random.c
r94980502 r0438091 7 7 8 8 int main() { 9 rand seed( getpid() ); // set random seed9 rand48seed( getpid() ); // set random seed 10 10 11 11 // test polymorphic calls to random and stream 12 char c = rand om();12 char c = rand48(); 13 13 sout  c  endl; 14 int i = rand om();14 int i = rand48(); 15 15 sout  i  endl; 16 unsigned int ui = rand om();16 unsigned int ui = rand48(); 17 17 sout  ui  endl; 18 long int li = rand om();18 long int li = rand48(); 19 19 sout  li  endl; 20 unsigned long int uli = rand om();20 unsigned long int uli = rand48(); 21 21 sout  uli  endl; 22 float f = rand om();22 float f = rand48(); 23 23 sout  f  endl; 24 double d = rand om();24 double d = rand48(); 25 25 sout  d  endl; 26 float _Complex fc = rand om();26 float _Complex fc = rand48(); 27 27 sout  fc  endl; 28 double _Complex dc = rand om();28 double _Complex dc = rand48(); 29 29 sout  dc  endl; 30 long double _Complex ldc = rand om();30 long double _Complex ldc = rand48(); 31 31 sout  ldc  endl; 32 32 } // main 
src/libcfa/builtins.cf
r94980502 r0438091 584 584 int __builtin_LINE(); 585 585 extern const char *__PRETTY_FUNCTION__; 586 typedef int wchar_t; 
src/libcfa/stdlib
r94980502 r0438091 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 17:38:21201613 // Update Count : 6 412 // Last Modified On : Tue Mar 22 22:34:24 2016 13 // Update Count : 69 14 14 // 15 15 … … 19 19 #include <stddef.h> // size_t 20 20 } // extern "C" 21 22 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill23 forall( otype T ) T * memset( T * ptr ); // remove when default value available24 21 25 22 forall( otype T ) T * malloc( void ); … … 34 31 forall( otype T ) T * memalign( size_t alignment ); // deprecated 35 32 forall( otype T ) int posix_memalign( T ** ptr, size_t alignment ); 33 34 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill 35 forall( otype T ) T * memset( T * ptr ); // remove when default value available 36 36 37 37 // … … 93 93 // 94 94 95 void rand seed( long int s );96 char rand om();97 int rand om();98 unsigned int rand om();99 long int rand om();100 unsigned long int rand om();101 float rand om();102 double rand om();103 float _Complex rand om();104 double _Complex rand om();105 long double _Complex rand om();95 void rand48seed( long int s ); 96 char rand48(); 97 int rand48(); 98 unsigned int rand48(); 99 long int rand48(); 100 unsigned long int rand48(); 101 float rand48(); 102 double rand48(); 103 float _Complex rand48(); 104 double _Complex rand48(); 105 long double _Complex rand48(); 106 106 107 107 // 
src/libcfa/stdlib.c
r94980502 r0438091 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 17:38:47201613 // Update Count : 14 312 // Last Modified On : Tue Mar 22 22:34:26 2016 13 // Update Count : 145 14 14 // 15 15 … … 26 26 #include <complex.h> // _Complex_I, cabsf, cabs, cabsl 27 27 } // extern "C" 28 29 forall( otype T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill30 printf( "memset1\n" );31 return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) );32 } // memset33 forall( otype T ) T * memset( T * ptr ) { // remove when default value available34 printf( "memset2\n" );35 return (T *)memset( ptr, 0, malloc_usable_size( ptr ) );36 } // memset37 28 38 29 forall( otype T ) T * malloc( void ) { … … 91 82 } // posix_memalign 92 83 84 forall( otype T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill 85 printf( "memset1\n" ); 86 return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) ); 87 } // memset 88 forall( otype T ) T * memset( T * ptr ) { // remove when default value available 89 printf( "memset2\n" ); 90 return (T *)memset( ptr, 0, malloc_usable_size( ptr ) ); 91 } // memset 92 93 93 // 94 94 … … 243 243 // 244 244 245 void rand seed( long int s ) { srand48( s ); }246 char rand om() { return lrand48(); }247 int rand om() { return mrand48(); }248 unsigned int rand om() { return lrand48(); }249 long int rand om() { return mrand48(); }250 unsigned long int rand om() { return lrand48(); }251 float rand om() { return (float)drand48(); } // otherwise float uses lrand48252 double rand om() { return drand48(); }253 float _Complex rand om() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }254 double _Complex rand om() { return drand48() + (double _Complex)(drand48() * _Complex_I); }255 long double _Complex rand om() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }245 void rand48seed( long int s ) { srand48( s ); } 246 char rand48() { return lrand48(); } 247 int rand48() { return mrand48(); } 248 unsigned int rand48() { return lrand48(); } 249 long int rand48() { return mrand48(); } 250 unsigned long int rand48() { return lrand48(); } 251 float rand48() { return (float)drand48(); } // otherwise float uses lrand48 252 double rand48() { return drand48(); } 253 float _Complex rand48() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); } 254 double _Complex rand48() { return drand48() + (double _Complex)(drand48() * _Complex_I); } 255 long double _Complex rand48() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); } 256 256 257 257 //
Note: See TracChangeset
for help on using the changeset viewer.