Changeset 0438091


Ignore:
Timestamp:
Mar 22, 2016, 10:39:34 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, string, with_gc
Children:
6a57da5
Parents:
94980502
Message:

modify stdlib random to not use C library routine

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/examples/random.c

    r94980502 r0438091  
    77
    88int main() {
    9         randseed( getpid() );                                                           // set random seed
     9        rand48seed( getpid() );                                                         // set random seed
    1010
    1111        // test polymorphic calls to random and stream
    12         char c = random();
     12        char c = rand48();
    1313        sout | c | endl;
    14         int i = random();
     14        int i = rand48();
    1515    sout | i | endl;
    16         unsigned int ui = random();
     16        unsigned int ui = rand48();
    1717    sout | ui | endl;
    18         long int li = random();
     18        long int li = rand48();
    1919    sout | li | endl;
    20         unsigned long int uli = random();
     20        unsigned long int uli = rand48();
    2121    sout | uli | endl;
    22     float f = random();
     22    float f = rand48();
    2323    sout | f | endl;
    24     double d = random();
     24    double d = rand48();
    2525    sout | d | endl;
    26     float _Complex fc = random();
     26    float _Complex fc = rand48();
    2727    sout | fc | endl;
    28     double _Complex dc = random();
     28    double _Complex dc = rand48();
    2929    sout | dc | endl;
    30     long double _Complex ldc = random();
     30    long double _Complex ldc = rand48();
    3131    sout | ldc | endl;
    3232} // main
  • src/libcfa/builtins.cf

    r94980502 r0438091  
    584584int __builtin_LINE();
    585585extern const char *__PRETTY_FUNCTION__;
    586 typedef int wchar_t;
  • src/libcfa/stdlib

    r94980502 r0438091  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:38:21 2016
    13 // Update Count     : 64
     12// Last Modified On : Tue Mar 22 22:34:24 2016
     13// Update Count     : 69
    1414//
    1515
     
    1919#include <stddef.h>                                                                             // size_t
    2020} // extern "C"
    21 
    22 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
    23 forall( otype T ) T * memset( T * ptr );                                        // remove when default value available
    2421
    2522forall( otype T ) T * malloc( void );
     
    3431forall( otype T ) T * memalign( size_t alignment );             // deprecated
    3532forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
     33
     34forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
     35forall( otype T ) T * memset( T * ptr );                                // remove when default value available
    3636
    3737//---------------------------------------
     
    9393//---------------------------------------
    9494
    95 void randseed( long int s );
    96 char random();
    97 int random();
    98 unsigned int random();
    99 long int random();
    100 unsigned long int random();
    101 float random();
    102 double random();
    103 float _Complex random();
    104 double _Complex random();
    105 long double _Complex random();
     95void rand48seed( long int s );
     96char rand48();
     97int rand48();
     98unsigned int rand48();
     99long int rand48();
     100unsigned long int rand48();
     101float rand48();
     102double rand48();
     103float _Complex rand48();
     104double _Complex rand48();
     105long double _Complex rand48();
    106106
    107107//---------------------------------------
  • src/libcfa/stdlib.c

    r94980502 r0438091  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:38:47 2016
    13 // Update Count     : 143
     12// Last Modified On : Tue Mar 22 22:34:26 2016
     13// Update Count     : 145
    1414//
    1515
     
    2626#include <complex.h>                                                                    // _Complex_I, cabsf, cabs, cabsl
    2727} // extern "C"
    28 
    29 forall( otype T ) T * memset( T * ptr, unsigned char fill ) { // use default value '\0' for fill
    30         printf( "memset1\n" );
    31     return (T *)memset( ptr, (int)fill, malloc_usable_size( ptr ) );
    32 } // memset
    33 forall( otype T ) T * memset( T * ptr ) {                               // remove when default value available
    34         printf( "memset2\n" );
    35     return (T *)memset( ptr, 0, malloc_usable_size( ptr ) );
    36 } // memset
    3728
    3829forall( otype T ) T * malloc( void ) {
     
    9182} // posix_memalign
    9283
     84forall( 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
     88forall( 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
    9393//---------------------------------------
    9494
     
    243243//---------------------------------------
    244244
    245 void randseed( long int s ) { srand48( s ); }
    246 char random() { return lrand48(); }
    247 int random() { return mrand48(); }
    248 unsigned int random() { return lrand48(); }
    249 long int random() { return mrand48(); }
    250 unsigned long int random() { return lrand48(); }
    251 float random() { return (float)drand48(); }                             // otherwise float uses lrand48
    252 double random() { return drand48(); }
    253 float _Complex random() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
    254 double _Complex random() { return drand48() + (double _Complex)(drand48() * _Complex_I); }
    255 long double _Complex random() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
     245void rand48seed( long int s ) { srand48( s ); }
     246char rand48() { return lrand48(); }
     247int rand48() { return mrand48(); }
     248unsigned int rand48() { return lrand48(); }
     249long int rand48() { return mrand48(); }
     250unsigned long int rand48() { return lrand48(); }
     251float rand48() { return (float)drand48(); }                             // otherwise float uses lrand48
     252double rand48() { return drand48(); }
     253float _Complex rand48() { return (float)drand48() + (float _Complex)(drand48() * _Complex_I); }
     254double _Complex rand48() { return drand48() + (double _Complex)(drand48() * _Complex_I); }
     255long double _Complex rand48() { return (long double)drand48() + (long double _Complex)(drand48() * _Complex_I); }
    256256
    257257//---------------------------------------
Note: See TracChangeset for help on using the changeset viewer.