Search:

Type: Posts; User: flp1969

Page 1 of 20 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    12
    Views
    198

    Using RDRAND: // test.c - code for x86-64...

    Using RDRAND:

    // test.c - code for x86-64 (gcc).
    #include <stdio.h>
    #include <stdlib.h>
    #include <x86intrin.h>

    static int check_rdrand ( void );
    static double rand_ ( double, double );
  2. Replies
    12
    Views
    198

    You asked for a "platform neutral" method......

    You asked for a "platform neutral" method... rand() returns an uniform distributed random number in the range 0..RAND_MAX, usually through a LCG algorithm. In a 32 bit processor this is, again,...
  3. Replies
    12
    Views
    198

    #define swapd(a,b) ( double t_; t_ = (a); (a) =...

    #define swapd(a,b) ( double t_; t_ = (a); (a) = (b); (b) = t_; }

    double rand_range( double min, double max )
    {
    double r;

    if ( min > max )
    swapd( min, max );

    r = rand() /...
  4. Replies
    7
    Views
    109

    Ok. At this magnitude a long double has 1 ULP =...

    Ok. At this magnitude a long double has 1 ULP = 0.5. It means the imprecision is +/- 0.25. As for a double, 1 ULP = 1024 giving an imprecision of +/- 512. To illustrate, 5579207423999930400.0 cannot...
  5. Replies
    7
    Views
    109

    What do you mean "large values"? double supports...

    What do you mean "large values"? double supports values between +/-1.78769*10⁰⁸ (large enough for me).
    Using long double is always a overkill (large object representation in memory and no support...
  6. Replies
    4
    Views
    208

    And: 1- gethostbyname() is an old and obsolete...

    And:

    1- gethostbyname() is an old and obsolete function. Use getaddrinfo();
    2- sockaddr_in.sin_addr.s_addr is a simple 'unsigned int'. Don't need 'memcpy()' to write on it;
    3- Don't use...
  7. author='Your name here' for file in *.c; do ...

    author='Your name here'
    for file in *.c; do
    sed -i "s/<File Name>/$file/;s/<Author>/$author/;s/<Date>/$(date)/" $file
    done
  8. Replies
    7
    Views
    474

    ridderunnersjw, think of pointers as types that...

    ridderunnersjw, think of pointers as types that hold an address and addresses are unsigned integers (linke indices of an array). In C there are a difference in declaring an object and using it. If...
  9. Ahhh... of course, since we change the scale from...

    Ahhh... of course, since we change the scale from 2⁰ to 2⁻! Nice catch.
  10. Replies
    3
    Views
    380

    Looks like you are trying to mimic the asprintf()...

    Looks like you are trying to mimic the asprintf() GNU's function:


    #include <stdio.h>
    #include <stdlib.h>
    #include <stdarg.h>

    int asprintf ( char **p, char *fmt, ... )
    {
    int size;
  11. Replies
    6
    Views
    402

    There are some predefined symbols for Windows:...

    There are some predefined symbols for Windows: _WIN32 (this exists on mingw and VC++), __WINNT__
  12. That's interesting, Malcom! I completely forgot...

    That's interesting, Malcom! I completely forgot about linear interpolation!


    #include <stdlib.h>
    #include <float.h>

    #define lerp(min_, max_, norm) \
    ( (min_)*(1.0 - (norm)) + (max_)*(norm)...
  13. In time: You are correct about the duplicates....

    In time: You are correct about the duplicates. There are none. My mistake.
  14. That's a common mistake. The precision of a...

    That's a common mistake. The precision of a floating point type is measured in bits, not decimal digits. In the case of a `double` type, using IEEE 754 format, if you have all the 53 bits set (the...
  15. Hummm... sorry again, john.c... Taking another...

    Hummm... sorry again, john.c... Taking another look, your approach use the range between -0.999999999068677425384521484375 and 0.999999999068677425384521484375, inclusive. Mine is wider, from...
  16. Interesting the use of casting to unsigned int to...

    Interesting the use of casting to unsigned int to avoid overflows. I have only 1 consideration:

    RAND_MAX not necessarily is INT_MAX. It could be UINT_MAX. But, of course, rand() returns an int......
  17. My soluction: Reducing precision by 1 ULP. ...

    My soluction: Reducing precision by 1 ULP.


    #include <stdlib.h>
    #include <math.h>
    #include <float.h>

    // Transform rand() return value to [-1.0 e 1.0] range.
    #define XFRM_RAND(x) ( 2.0 *...
  18. INCLUDING these two is, of course, very easy....

    INCLUDING these two is, of course, very easy. Excluding them is easy too, but there is a trick.

    Of course, I'm waiting to see some code before showing it... :)
  19. Do you know how to get a random value in an...

    Do you know how to get a random value in an interval of 0 to 2?
    And... are you sure you need to exclude -1 and 1?
  20. Replies
    10
    Views
    561

    I adivce against this affirmative. For example: ...

    I adivce against this affirmative. For example:

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    #define N 10

    int main ( void )
    {
  21. Replies
    10
    Views
    561

    The rand() function is often implemented using a...

    The rand() function is often implemented using a "pseudo random number generator" called "linear congruence generator" (LCG). Most (if not all) "pseudo random number generators" depends on an initial...
  22. Replies
    10
    Views
    561

    You need to specify an initial "random" seed...

    You need to specify an initial "random" seed before using rand():


    #include <stdio.h>
    #include <stdlib.h>
    #ifndef _WIN32
    #include <unistd.h>
    #include <fcntl.h>
    #else
    #include <time.h>
  23. Replies
    10
    Views
    561

    Linear congruential generator - Wikipedia...

    Linear congruential generator - Wikipedia
  24. Anyway... try libpng: libpng Home Page...

    Anyway... try libpng: libpng Home Page (libpng-dev, on Debian/Ubuntu).
  25. ISO 9899:1999 (and beyond): 7.19.7.10 2:...

    ISO 9899:1999 (and beyond):

    7.19.7.10 2: "The puts function writes the string pointed to by s to the stream pointed to by stdout, and appends a new-line character to the output. The terminating...
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4