aboutsummaryrefslogtreecommitdiff
path: root/lib/std/special/compiler_rt/floatuntisf_test.zig
blob: 42379d808487ee876b872ed65d933b03486ea8fd (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
// SPDX-License-Identifier: MIT
// Copyright (c) 2015-2020 Zig Contributors
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
const __floatuntisf = @import("floatuntisf.zig").__floatuntisf;
const testing = @import("std").testing;

fn test__floatuntisf(a: u128, expected: f32) void {
    const x = __floatuntisf(a);
    testing.expect(x == expected);
}

test "floatuntisf" {
    test__floatuntisf(0, 0.0);

    test__floatuntisf(1, 1.0);
    test__floatuntisf(2, 2.0);
    test__floatuntisf(20, 20.0);

    test__floatuntisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
    test__floatuntisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);

    test__floatuntisf(make_ti(0x8000008000000000, 0), 0x1.000001p+127);
    test__floatuntisf(make_ti(0x8000000000000800, 0), 0x1.0p+127);
    test__floatuntisf(make_ti(0x8000010000000000, 0), 0x1.000002p+127);

    test__floatuntisf(make_ti(0x8000000000000000, 0), 0x1.000000p+127);

    test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);

    test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
    test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBACp+50);

    test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBBp+50);

    test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
    test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
    test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB9p+50);

    test__floatuntisf(0xFFFFFFFFFFFFFFFE, 0x1p+64);
    test__floatuntisf(0xFFFFFFFFFFFFFFFF, 0x1p+64);

    test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50);

    test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBAp+50);
    test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBAp+50);
    test__floatuntisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50);
    test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBCp+50);
    test__floatuntisf(0x0007FB72E8000001, 0x1.FEDCBAp+50);

    test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCBAp+50);
    test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCBAp+50);
    test__floatuntisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50);
    test__floatuntisf(0x0007FB72E4000001, 0x1.FEDCBAp+50);
    test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB8p+50);

    test__floatuntisf(make_ti(0x0000000000001FED, 0xCB90000000000001), 0x1.FEDCBAp+76);
    test__floatuntisf(make_ti(0x0000000000001FED, 0xCBA0000000000000), 0x1.FEDCBAp+76);
    test__floatuntisf(make_ti(0x0000000000001FED, 0xCBAFFFFFFFFFFFFF), 0x1.FEDCBAp+76);
    test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000000), 0x1.FEDCBCp+76);
    test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000001), 0x1.FEDCBCp+76);
    test__floatuntisf(make_ti(0x0000000000001FED, 0xCBBFFFFFFFFFFFFF), 0x1.FEDCBCp+76);
    test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000000), 0x1.FEDCBCp+76);
    test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000001), 0x1.FEDCBCp+76);
    test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000000), 0x1.FEDCBCp+76);
    test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000001), 0x1.FEDCBEp+76);
    test__floatuntisf(make_ti(0x0000000000001FED, 0xCBDFFFFFFFFFFFFF), 0x1.FEDCBEp+76);
    test__floatuntisf(make_ti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76);
}

fn make_ti(high: u64, low: u64) u128 {
    var result: u128 = high;
    result <<= 64;
    result |= low;
    return result;
}