• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stillwater-sc / universal / 24863773859

23 Apr 2026 11:12PM UTC coverage: 84.344% (-0.05%) from 84.39%
24863773859

Pull #716

github

web-flow
Merge 60ecd8596 into a9b924afc
Pull Request #716: feat(blockbinary): promote arithmetic operators to constexpr (PR 2 of #713)

30 of 48 new or added lines in 3 files covered. (62.5%)

21 existing lines in 4 files now uncovered.

44894 of 53227 relevant lines covered (84.34%)

6505249.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.57
/internal/blockbinary/api/constexpr.cpp
1
//  constexpr.cpp : compile-time tests for constexpr of blockbinary type
2
//
3
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
4
// SPDX-License-Identifier: MIT
5
//
6
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
7
#include <universal/utility/directives.hpp>
8
#include <universal/utility/long_double.hpp>
9
#include <iostream>
10

11
#include <universal/internal/blockbinary/blockbinary.hpp>
12
#include <universal/verification/test_suite.hpp>
13

14
int main()
1✔
15
try {
16
        using namespace sw::universal;
17

18
        std::string test_suite  = "blockbinary constexpr compile-time validation";
2✔
19
        std::string test_tag    = "constexpr";
1✔
20
        bool reportTestCases    = true;
1✔
21
        int nrOfFailedTestCases = 0;
1✔
22

23
        ReportTestSuiteHeader(test_suite, reportTestCases);
1✔
24

25
        {
26
                constexpr blockbinary<8, uint8_t> b8_1b(0x5555);
1✔
27
                constexpr blockbinary<8, uint16_t> b8_2b(0x5555);
1✔
28
                constexpr blockbinary<8, uint32_t> b8_4b(0x5555);
1✔
29

30
                std::cout << b8_1b << '\n' << b8_2b << '\n' << b8_4b << '\n';
1✔
31
        }
32

33
        {
34
                constexpr blockbinary<16, uint8_t> b16_2(0x5555);
1✔
35
                constexpr blockbinary<16, uint16_t> b16_1(0x5555);
1✔
36
                constexpr blockbinary<16, uint32_t> b16_4b(0x5555);
1✔
37

38
                std::cout << b16_1 << '\n' << b16_2 << '\n' << b16_4b << '\n';
1✔
39
        }
40

41
        // constexpr arithmetic (issue #715)
42
        {
43
                using BB = blockbinary<32, std::uint8_t, BinaryNumberType::Signed>;
44

45
                // constexpr operator+= via lambda
46
                constexpr BB sum = []() { BB t(5); t += BB(7); return t; }();
1✔
47
                static_assert(sum.block(0) == 12, "constexpr blockbinary<32,uint8>(5) += 7 == 12");
48

49
                // constexpr operator++
50
                constexpr BB inc = []() { BB t(0); ++t; ++t; ++t; return t; }();
1✔
51
                static_assert(inc.block(0) == 3, "constexpr blockbinary<32,uint8> ++x3 == 3");
52

53
                // constexpr operator<<=
54
                constexpr BB shl = []() { BB t(1); t <<= 5; return t; }();
1✔
55
                static_assert(shl.block(0) == 32, "constexpr blockbinary<32,uint8>(1) <<= 5 == 32");
56

57
                // constexpr operator|=
58
                constexpr BB orResult = []() { BB t(0xF); t |= BB(0xF0); return t; }();
1✔
59
                static_assert(orResult.block(0) == 0xFF, "constexpr blockbinary<32,uint8>(0xF) |= 0xF0 == 0xFF");
60

61
                // constexpr free twosComplement (negation)
62
                constexpr BB neg = twosComplement(BB(5));
1✔
63
                static_assert(neg.block(0) == 0xFB, "constexpr twosComplement(blockbinary<32,uint8>(5)) low byte == 0xFB");
64

65
                // multi-block uint8 carry across limbs
66
                using BB64u8 = blockbinary<64, std::uint8_t, BinaryNumberType::Signed>;
67
                constexpr BB64u8 carryAcross = []() { BB64u8 t(123); t += BB64u8(456); return t; }();
1✔
68
                // 123 + 456 = 579 = 0x243
69
                static_assert(carryAcross.block(0) == 0x43, "constexpr 123+456 low byte");
70
                static_assert(carryAcross.block(1) == 0x02, "constexpr 123+456 high byte (carry)");
71

72
                // uint64 limb arithmetic via std::is_constant_evaluated portable carry path
73
                using BB128u64 = blockbinary<128, std::uint64_t, BinaryNumberType::Signed>;
74
                constexpr BB128u64 u128inc = []() { BB128u64 t(0); ++t; return t; }();
1✔
75
                static_assert(u128inc.block(0) == 1, "constexpr 2-limb uint64 ++ low limb");
76
                static_assert(u128inc.block(1) == 0, "constexpr 2-limb uint64 ++ high limb");
77

78
                std::cout << "constexpr arithmetic smoke tests PASS (compile-time)\n";
1✔
79
        }
80

81
        ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
1✔
82
        return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
1✔
83
}
1✔
NEW
84
catch (char const* msg) {
×
NEW
85
        std::cerr << msg << '\n';
×
NEW
86
        return EXIT_FAILURE;
×
NEW
87
}
×
NEW
88
catch (const std::runtime_error& err) {
×
NEW
89
        std::cerr << "Uncaught runtime exception: " << err.what() << std::endl;
×
NEW
90
        return EXIT_FAILURE;
×
NEW
91
}
×
UNCOV
92
catch (...) {
×
UNCOV
93
        std::cerr << "Caught unknown exception" << '\n';
×
UNCOV
94
        return EXIT_FAILURE;
×
95
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc