Mail Archives: djgpp-workers/2000/07/12/12:42:20
FYI, I've implemented a faster erand48 from the suggestions from Dieter.
Right,
MartinS
Patch (pasted):
? src/libc/compat/stdlib/.rand48.safe
Index: src/libc/compat/stdlib/rand48.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/compat/stdlib/rand48.c,v
retrieving revision 1.1
diff -r1.1 rand48.c
4c4
< * Copyright (C) 1999 Martin Str<94>mberg <ams AT ludd DOT luth DOT se>.
---
> * Copyright (C) 1999, 2000 Martin Str@"omberg <ams AT ludd DOT luth DOT se>.
57,59c57,58
< int i; /* Counter. */
< double pot = 0.5; /* A potential of 0.5. */
< double result = 0.0;
---
> /* Thanks to Dieter Buerssner for showing how it ought to be done. */
> signed long long ll; /* Temporary result holder. */
63,80c62,64
< for(i = 0; i < 8*sizeof(unsigned short); i++)
< {
< if( (state[2] << i) & 0x8000 )
< {
< result += pot;
< }
< pot /= 2.0;
< if( (state[1] << i) & 0x8000 )
< {
< result += pot;
< }
< pot /= 2.0;
< if( (state[0] << i) & 0x8000 )
< {
< result += pot;
< }
< pot /= 2.0;
< }
---
> ll = (signed long long)( state[0]
> | ( (unsigned long)state[1] ) << 16
> | ( (unsigned long long)state[2] ) << 32 );
82c66
< return(result);
---
> return(ll * ( 1.0 / ( 1LL << 48 ) ) );
- Raw text -