update for HEAD-2003021201
[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 unsigned int _rotl( unsigned int value, int shift )
15 {
16         int max_bits = sizeof(unsigned int)<<3;
17         if ( shift < 0 )
18                 return _rotr(value,-shift);
19
20         if ( shift > max_bits )
21                 shift = shift % max_bits;
22         return (value << shift) | (value >> (max_bits-shift));
23 }
24
25 unsigned int _rotr( unsigned int value, int shift )
26 {
27         int max_bits = sizeof(unsigned int)<<3;
28         if ( shift < 0 )
29                 return _rotl(value,-shift);
30
31         if ( shift > max_bits<<3 )
32                 shift = shift % max_bits;
33         return (value >> shift) | (value <<  (max_bits-shift));
34 }
35
36
37 unsigned long _lrotl( unsigned long value, int shift )
38 {
39         int max_bits = sizeof(unsigned long)<<3;
40         if ( shift < 0 )
41                 return _lrotr(value,-shift);
42
43         if ( shift > max_bits )
44                 shift = shift % max_bits;
45         return (value << shift) | (value >> (max_bits-shift));
46 }
47
48 unsigned long _lrotr( unsigned long value, int shift )
49 {
50         int max_bits = sizeof(unsigned long)<<3;
51         if ( shift < 0 )
52                 return _lrotl(value,-shift);
53
54         if ( shift > max_bits )
55                 shift = shift % max_bits;
56         return (value >> shift) | (value << (max_bits-shift));
57 }