update for HEAD-2003091401
[reactos.git] / lib / crtdll / stdlib / rot.c
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS system libraries
4  * FILE:        lib/crtdll/stdlib/rot.c
5  * PURPOSE:     Performs a bit wise rotation
6  * PROGRAMER:   Boudewijn Dekker
7  * UPDATE HISTORY:
8  *              03/04/99: Created
9  */
10
11 #include <msvcrt/stdlib.h>
12 #include <msvcrt/crttypes.h>
13
14 /*
15  * @implemented
16  */
17 unsigned int _rotl( unsigned int value, int shift )
18 {
19         int max_bits = sizeof(unsigned int)<<3;
20         if ( shift < 0 )
21                 return _rotr(value,-shift);
22
23         if ( shift > max_bits )
24                 shift = shift % max_bits;
25         return (value << shift) | (value >> (max_bits-shift));
26 }
27
28 /*
29  * @implemented
30  */
31 unsigned int _rotr( unsigned int value, int shift )
32 {
33         int max_bits = sizeof(unsigned int)<<3;
34         if ( shift < 0 )
35                 return _rotl(value,-shift);
36
37         if ( shift > max_bits<<3 )
38                 shift = shift % max_bits;
39         return (value >> shift) | (value <<  (max_bits-shift));
40 }
41
42
43 /*
44  * @implemented
45  */
46 unsigned long _lrotl( unsigned long value, int shift )
47 {
48         int max_bits = sizeof(unsigned long)<<3;
49         if ( shift < 0 )
50                 return _lrotr(value,-shift);
51
52         if ( shift > max_bits )
53                 shift = shift % max_bits;
54         return (value << shift) | (value >> (max_bits-shift));
55 }
56
57 /*
58  * @implemented
59  */
60 unsigned long _lrotr( unsigned long value, int shift )
61 {
62         int max_bits = sizeof(unsigned long)<<3;
63         if ( shift < 0 )
64                 return _lrotl(value,-shift);
65
66         if ( shift > max_bits )
67                 shift = shift % max_bits;
68         return (value >> shift) | (value << (max_bits-shift));
69 }