1 // RUNNABLE_PHOBOS_TEST
2 
3 import std.stdio;
4 import std.math;
5 import core.bitop;
6 
version(DigitalMars)7 version (DigitalMars)
8 {
9     version (X86_64)
10         version = AnyX86;
11     else version (X86)
12         version = AnyX86;
13 }
14 
15 /*******************************************/
16 
test1()17 void test1()
18 {
19     writefln("%a", sin(6.8L));
20     auto f = 6.8L;
21     writefln("%a", sin(f));
22     assert(sin(f) == sin(6.8L));
23     static assert(approxEqual(sin(6.8L), 0x1.f9f8d9aea10fdf1cp-2));
24 
25     writefln("%a", cos(6.8L));
26     f = 6.8L;
27     writefln("%a", cos(f));
28     assert(cos(f) == cos(6.8L));
29     static assert(approxEqual(cos(6.8L), 0x1.bd21aaf88dcfa13ap-1));
30 
31     writefln("%a", tan(6.8L));
32     f = 6.8L;
33     writefln("%a", tan(f));
34     version (Win64)
35     { }
36     else
37         assert(tan(f) == tan(6.8L));
38     static assert(approxEqual(tan(6.8L), 0x1.22fd752af75cd08cp-1));
39 }
40 
41 /*******************************************/
42 
test2()43 void test2()
44 {
45     float i = 3;
46     i = i ^^ 2;
47     assert(i == 9);
48 
49     int j = 2;
50     j = j ^^ 1;
51     assert(j == 2);
52 
53     i = 4;
54     i = i ^^ .5;
55     assert(i == 2);
56 }
57 
58 /**** Bug 5703 *****************************/
59 
60 static assert({
61     int a = 0x80;
62     int f = bsf(a);
63     int r = bsr(a);
64     a = 0x22;
65     assert(bsf(a)==1);
66     assert(bsr(a)==5);
67     a = 0x8000000;
68     assert(bsf(a)==27);
69     assert(bsr(a)==27);
70     a = 0x13f562c0;
71     assert(bsf(a) == 6);
72     assert(bsr(a) == 28);
73     assert(bswap(0xAABBCCDD) == 0xDDCCBBAA);
74     return true;
75 }());
76 
77 /*******************************************/
78 
test3()79 void test3()
80 {
81     version (AnyX86)
82     {
83         static assert( _popcnt( cast(ushort)0 ) == 0 );
84         static assert( _popcnt( cast(ushort)7 ) == 3 );
85         static assert( _popcnt( cast(ushort)0xAA )== 4);
86         static assert( _popcnt( cast(ushort)0xFFFF ) == 16 );
87         static assert( _popcnt( cast(ushort)0xCCCC ) == 8 );
88         static assert( _popcnt( cast(ushort)0x7777 ) == 12 );
89         static assert( _popcnt( cast(uint)0 ) == 0 );
90         static assert( _popcnt( cast(uint)7 ) == 3 );
91         static assert( _popcnt( cast(uint)0xAA )== 4);
92         static assert( _popcnt( cast(uint)0x8421_1248 ) == 8 );
93         static assert( _popcnt( cast(uint)0xFFFF_FFFF ) == 32 );
94         static assert( _popcnt( cast(uint)0xCCCC_CCCC ) == 16 );
95         static assert( _popcnt( cast(uint)0x7777_7777 ) == 24 );
96         version (X86_64)
97         {
98             static assert( _popcnt( cast(ulong)0 ) == 0 );
99             static assert( _popcnt( cast(ulong)7 ) == 3 );
100             static assert( _popcnt( cast(ulong)0xAA )== 4);
101             static assert( _popcnt( cast(ulong)0x8421_1248 ) == 8 );
102             static assert( _popcnt( cast(ulong)0xFFFF_FFFF_FFFF_FFFF ) == 64 );
103             static assert( _popcnt( cast(ulong)0xCCCC_CCCC_CCCC_CCCC ) == 32 );
104             static assert( _popcnt( cast(ulong)0x7777_7777_7777_7777 ) == 48 );
105         }
106     }
107 }
108 
109 /*******************************************/
110 
main()111 int main()
112 {
113     test1();
114     test2();
115     test3();
116 
117     printf("Success\n");
118     return 0;
119 }
120