Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:ClickHouse ClickHouse Wide Integer

From Leeroopedia


Knowledge Sources
Domains Numeric_Types, Arithmetic
Last Updated 2026-02-08 00:00 GMT

Overview

Multi-precision integer arithmetic for 128 and 256-bit integers.

Description

Provides integer<Bits, Signed> template for arbitrary-precision integers. Implements all arithmetic, bitwise, and comparison operators.

Usage

Use for cryptography, exact large number calculations, or when 64-bit integers are insufficient.

Code Reference

Source Location

Signature

template <size_t Bits, typename Signed>
class integer {
public:
    using base_type = uint64_t;
    
    constexpr integer() noexcept = default;
    template <typename T> constexpr integer(T rhs) noexcept;
    
    // Arithmetic operators
    template <typename Arithmetic>
    constexpr integer & operator += (const Arithmetic & rhs);
    constexpr integer & operator *= (const Arithmetic & rhs);
    // ... all arithmetic operators
    
    // Conversions
    template <std::integral T> constexpr explicit operator T() const noexcept;
    constexpr operator double() const noexcept;
};

Import

#include <base/wide_integer.h>

Usage Examples

#include <base/wide_integer.h>

Int128 a = 123456789012345678901234567890_i128;
Int128 b = 987654321098765432109876543210_i128;

Int128 sum = a + b;
Int128 product = a * b;
bool less = a < b;

// Convert to double
double approx = static_cast<double>(a);

// 256-bit arithmetic
UInt256 huge1 = /* ... */;
UInt256 huge2 = /* ... */;
UInt256 result = huge1 * huge2;

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment