From: Martin Str|mberg Message-Id: <200007121642.SAA23906@father.ludd.luth.se> Subject: Quicker erand48 patch To: djgpp-workers AT delorie DOT com (DJGPP-WORKERS) Date: Wed, 12 Jul 2000 18:42:03 +0200 (MET DST) X-Mailer: ELM [version 2.4ME+ PL54 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com 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 . --- > * Copyright (C) 1999, 2000 Martin Str@"omberg . 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 ) ) );