summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/runnable/builtin.d
blob: d7ac356757ff6da6059cc6bab404acbc2c579724 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import std.stdio;
import std.math;
import core.bitop;

version (DigitalMars)
{
    version (X86_64)
        version = AnyX86;
    else version (X86)
        version = AnyX86;
}

/*******************************************/

void test1()
{
    writefln("%a", sin(6.8L));
    auto f = 6.8L;
    writefln("%a", sin(f));
    assert(sin(f) == sin(6.8L));
    static assert(approxEqual(sin(6.8L), 0x1.f9f8d9aea10fdf1cp-2));

    writefln("%a", cos(6.8L));
    f = 6.8L;
    writefln("%a", cos(f));
    assert(cos(f) == cos(6.8L));
    static assert(approxEqual(cos(6.8L), 0x1.bd21aaf88dcfa13ap-1));

    writefln("%a", tan(6.8L));
    f = 6.8L;
    writefln("%a", tan(f));
    version (Win64)
    { }
    else
        assert(tan(f) == tan(6.8L));
    static assert(approxEqual(tan(6.8L), 0x1.22fd752af75cd08cp-1));
}

/*******************************************/

void test2()
{
    float i = 3;
    i = i ^^ 2;
    assert(i == 9);

    int j = 2;
    j = j ^^ 1;
    assert(j == 2);

    i = 4;
    i = i ^^ .5;
    assert(i == 2);
}

/**** Bug 5703 *****************************/

static assert({
    int a = 0x80;
    int f = bsf(a);
    int r = bsr(a);
    a = 0x22;
    assert(bsf(a)==1);
    assert(bsr(a)==5);
    a = 0x8000000;
    assert(bsf(a)==27);
    assert(bsr(a)==27);
    a = 0x13f562c0;
    assert(bsf(a) == 6);
    assert(bsr(a) == 28);
    assert(bswap(0xAABBCCDD) == 0xDDCCBBAA);
    return true;
}());

/*******************************************/

void test3()
{
    version (AnyX86)
    {
        static assert( _popcnt( cast(ushort)0 ) == 0 );
        static assert( _popcnt( cast(ushort)7 ) == 3 );
        static assert( _popcnt( cast(ushort)0xAA )== 4);
        static assert( _popcnt( cast(ushort)0xFFFF ) == 16 );
        static assert( _popcnt( cast(ushort)0xCCCC ) == 8 );
        static assert( _popcnt( cast(ushort)0x7777 ) == 12 );
        static assert( _popcnt( cast(uint)0 ) == 0 );
        static assert( _popcnt( cast(uint)7 ) == 3 );
        static assert( _popcnt( cast(uint)0xAA )== 4);
        static assert( _popcnt( cast(uint)0x8421_1248 ) == 8 );
        static assert( _popcnt( cast(uint)0xFFFF_FFFF ) == 32 );
        static assert( _popcnt( cast(uint)0xCCCC_CCCC ) == 16 );
        static assert( _popcnt( cast(uint)0x7777_7777 ) == 24 );
        version (X86_64)
        {
            static assert( _popcnt( cast(ulong)0 ) == 0 );
            static assert( _popcnt( cast(ulong)7 ) == 3 );
            static assert( _popcnt( cast(ulong)0xAA )== 4);
            static assert( _popcnt( cast(ulong)0x8421_1248 ) == 8 );
            static assert( _popcnt( cast(ulong)0xFFFF_FFFF_FFFF_FFFF ) == 64 );
            static assert( _popcnt( cast(ulong)0xCCCC_CCCC_CCCC_CCCC ) == 32 );
            static assert( _popcnt( cast(ulong)0x7777_7777_7777_7777 ) == 48 );
        }
    }
}

/*******************************************/

int main()
{
    test1();
    test2();
    test3();

    printf("Success\n");
    return 0;
}
// RUNNABLE_PHOBOS_TEST