ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libecb/ecb.pod
(Generate patch)

Comparing libecb/ecb.pod (file contents):
Revision 1.5 by root, Thu May 26 20:05:55 2011 UTC vs.
Revision 1.6 by root, Thu May 26 20:06:43 2011 UTC

710..n-1, then you could use this inline function in a header file: 710..n-1, then you could use this inline function in a header file:
72 72
73 ecb_inline uint32_t 73 ecb_inline uint32_t
74 rndm (uint32_t n) 74 rndm (uint32_t n)
75 { 75 {
76 return n * (uint32_t)rndm16 ()) >> 16; 76 return (n * (uint32_t)rndm16 ()) >> 16;
77 } 77 }
78 78
79However, for powers of two, you could use a normal mask, but that is only 79However, for powers of two, you could use a normal mask, but that is only
80worth it if, at compile time, you can detect this case. This is the case 80worth it if, at compile time, you can detect this case. This is the case
81when the passed number is a constant and also a power of two (C<n & (n - 81when the passed number is a constant and also a power of two (C<n & (n -
84 ecb_inline uint32_t 84 ecb_inline uint32_t
85 rndm (uint32_t n) 85 rndm (uint32_t n)
86 { 86 {
87 return is_constant (n) && !(n & (n - 1)) 87 return is_constant (n) && !(n & (n - 1))
88 ? rndm16 () & (num - 1) 88 ? rndm16 () & (num - 1)
89 : (uint32_t)rndm16 ()) >> 16; 89 : (n * (uint32_t)rndm16 ()) >> 16;
90 } 90 }
91 91
92=item bool ecb_expect(expr,value) 92=item bool ecb_expect(expr,value)
93 93
94=item bool ecb_unlikely(bool) 94=item bool ecb_unlikely(bool)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines