<commit_before>/*
 * c8.h
 */
#ifndef __C8_H
#define __C8_H

#include <cstring>
#include <iostream>
#include <memory>
#include <string>
#include <cstdint>

/*
 * Macros to allow the compiler to make better choices about code structure.
 */
#define C8_LIKELY(x) __builtin_expect(!!(x), 1)
#define C8_UNLIKELY(x) __builtin_expect(!!(x), 0)

namespace c8 {
    /*
     * Exception class to signal an invalid argument.
     */
    class invalid_argument : public std::invalid_argument {
    public:
        invalid_argument(const std::string &s) : std::invalid_argument(s) {
        }
    };

    /*
     * Exception class to signal an overflow.
     */
    class overflow_error : public std::overflow_error {
    public:
        overflow_error() : std::overflow_error("overflow error") {
        }
    };

    /*
     * Exception class to signal an underflow.
     */
    class underflow_error : public std::underflow_error {
    public:
        underflow_error() : std::underflow_error("underflow error") {
        }
    };

    /*
     * Exception class to signal divide-by-zero.
     */
    class divide_by_zero : public std::runtime_error {
    public:
        divide_by_zero() : std::runtime_error("divide by zero") {
        }
    };

    /*
     * Exception class to signal not a number.
     */
    class not_a_number : public std::runtime_error {
    public:
        not_a_number() : std::runtime_error("not a number") {
        }
    };

    /*
     * Define the concepts of a "digit" and a "double digit" (twice the size of a digit.
     * A digit is much larger than a numeral, but the algorithms we use for things like
     * addition, subtraction, multiplication and division all work just the same, whether
     * our digits are 1 bit, 32 bits or range from 0 to 9.
     *
     * Other versions that would work here:
     *
     * typedef uint16_t natural_digit;
     * typedef uint32_t natural_double_digit;
     *
     * Or:
     *
     * typedef uint8_t natural_digit;
     * typedef uint16_t natural_double_digit;
     *
     * Or:
     *
     * typedef uint32_t natural_digit;
     * typedef uint64_t natural_double_digit;
     */
    typedef uint64_t natural_digit;
    typedef unsigned __int128 natural_double_digit;

    const std::size_t natural_digit_bits = 8 * sizeof(natural_digit);

    class natural {
    public:
        /*
         * Constructors.
         */
        natural() noexcept {
            num_digits_ = 0;
            digits_size_ = sizeof(small_digits_) / sizeof(natural_digit);
            digits_ = small_digits_;
        }

        natural(unsigned long long v) noexcept;
        natural(const std::string &v);
        natural(const natural &v);
        natural(natural &&v) noexcept;

        ~natural() = default;

        auto operator ==(const natural &v) const noexcept -> bool;
        auto operator !=(const natural &v) const noexcept -> bool;
        auto operator >(const natural &v) const noexcept -> bool;
        auto operator >=(const natural &v) const noexcept -> bool;
        auto operator <(const natural &v) const noexcept -> bool;
        auto operator <=(const natural &v) const noexcept -> bool;

        auto operator +(const natural &v) const -> natural;
        auto operator -(const natural &v) const -> natural;
        auto operator *(const natural &v) const -> natural;
        auto operator /(const natural &v) const -> natural;
        auto operator %(const natural &v) const -> natural;
        auto operator <<(unsigned int count) const -> natural;
        auto operator >>(unsigned int count) const -> natural;

        auto operator =(const natural &v) -> natural &;
        auto operator =(natural &&v) noexcept -> natural &;
        auto operator +=(const natural &v) -> natural &;
        auto operator -=(const natural &v) -> natural &;
        auto operator <<=(unsigned int count) -> natural &;
        auto operator >>=(unsigned int count) -> natural &;
        auto operator *=(const natural &v) -> natural &;
        auto operator /=(const natural &v) -> natural &;
        auto operator %=(const natural &v) -> natural &;

        auto size_bits() const noexcept -> std::size_t;
        auto divide_modulus(const natural &v) const -> std::pair<natural, natural>;
        auto gcd(const natural &v) const -> natural;

        /*
         * Is this number zero?
         */
        auto is_zero() const noexcept -> bool {
            return (num_digits_ == 0) ? true : false;
        }

        auto to_unsigned_long_long() const -> unsigned long long;

        friend auto operator <<(std::ostream &outstr, const natural &v) -> std::ostream &;

    private:
        std::size_t num_digits_;        // The number of digits in this number
        std::size_t digits_size_;       // Number of digits_ allocated
        natural_digit *digits_;         // Digits of the natural number
        natural_digit small_digits_[32 / sizeof(natural_digit)];
                                        // Small fixed-size digit buffer
        std::unique_ptr<natural_digit[]> large_digits_;
                                        // Pointer to large digit buffer, if needed

        auto reserve(std::size_t new_digits) -> void;
        auto expand(std::size_t new_digits) -> void;
        auto copy_digits(const natural &v) -> void;<commit_msg>Make the "small" digit buffer larger<commit_after>/*
 * c8.h
 */
#ifndef __C8_H
#define __C8_H

#include <cstring>
#include <iostream>
#include <memory>
#include <string>
#include <cstdint>

/*
 * Macros to allow the compiler to make better choices about code structure.
 */
#define C8_LIKELY(x) __builtin_expect(!!(x), 1)
#define C8_UNLIKELY(x) __builtin_expect(!!(x), 0)

namespace c8 {
    /*
     * Exception class to signal an invalid argument.
     */
    class invalid_argument : public std::invalid_argument {
    public:
        invalid_argument(const std::string &s) : std::invalid_argument(s) {
        }
    };

    /*
     * Exception class to signal an overflow.
     */
    class overflow_error : public std::overflow_error {
    public:
        overflow_error() : std::overflow_error("overflow error") {
        }
    };

    /*
     * Exception class to signal an underflow.
     */
    class underflow_error : public std::underflow_error {
    public:
        underflow_error() : std::underflow_error("underflow error") {
        }
    };

    /*
     * Exception class to signal divide-by-zero.
     */
    class divide_by_zero : public std::runtime_error {
    public:
        divide_by_zero() : std::runtime_error("divide by zero") {
        }
    };

    /*
     * Exception class to signal not a number.
     */
    class not_a_number : public std::runtime_error {
    public:
        not_a_number() : std::runtime_error("not a number") {
        }
    };

    /*
     * Define the concepts of a "digit" and a "double digit" (twice the size of a digit.
     * A digit is much larger than a numeral, but the algorithms we use for things like
     * addition, subtraction, multiplication and division all work just the same, whether
     * our digits are 1 bit, 32 bits or range from 0 to 9.
     *
     * Other versions that would work here:
     *
     * typedef uint16_t natural_digit;
     * typedef uint32_t natural_double_digit;
     *
     * Or:
     *
     * typedef uint8_t natural_digit;
     * typedef uint16_t natural_double_digit;
     *
     * Or:
     *
     * typedef uint32_t natural_digit;
     * typedef uint64_t natural_double_digit;
     */
    typedef uint64_t natural_digit;
    typedef unsigned __int128 natural_double_digit;

    const std::size_t natural_digit_bits = 8 * sizeof(natural_digit);

    class natural {
    public:
        /*
         * Constructors.
         */
        natural() noexcept {
            num_digits_ = 0;
            digits_size_ = sizeof(small_digits_) / sizeof(natural_digit);
            digits_ = small_digits_;
        }

        natural(unsigned long long v) noexcept;
        natural(const std::string &v);
        natural(const natural &v);
        natural(natural &&v) noexcept;

        ~natural() = default;

        auto operator ==(const natural &v) const noexcept -> bool;
        auto operator !=(const natural &v) const noexcept -> bool;
        auto operator >(const natural &v) const noexcept -> bool;
        auto operator >=(const natural &v) const noexcept -> bool;
        auto operator <(const natural &v) const noexcept -> bool;
        auto operator <=(const natural &v) const noexcept -> bool;

        auto operator +(const natural &v) const -> natural;
        auto operator -(const natural &v) const -> natural;
        auto operator *(const natural &v) const -> natural;
        auto operator /(const natural &v) const -> natural;
        auto operator %(const natural &v) const -> natural;
        auto operator <<(unsigned int count) const -> natural;
        auto operator >>(unsigned int count) const -> natural;

        auto operator =(const natural &v) -> natural &;
        auto operator =(natural &&v) noexcept -> natural &;
        auto operator +=(const natural &v) -> natural &;
        auto operator -=(const natural &v) -> natural &;
        auto operator <<=(unsigned int count) -> natural &;
        auto operator >>=(unsigned int count) -> natural &;
        auto operator *=(const natural &v) -> natural &;
        auto operator /=(const natural &v) -> natural &;
        auto operator %=(const natural &v) -> natural &;

        auto size_bits() const noexcept -> std::size_t;
        auto divide_modulus(const natural &v) const -> std::pair<natural, natural>;
        auto gcd(const natural &v) const -> natural;

        /*
         * Is this number zero?
         */
        auto is_zero() const noexcept -> bool {
            return (num_digits_ == 0) ? true : false;
        }

        auto to_unsigned_long_long() const -> unsigned long long;

        friend auto operator <<(std::ostream &outstr, const natural &v) -> std::ostream &;

    private:
        std::size_t num_digits_;        // The number of digits in this number
        std::size_t digits_size_;       // Number of digits_ allocated
        natural_digit *digits_;         // Digits of the natural number
        natural_digit small_digits_[64 / sizeof(natural_digit)];
                                        // Small fixed-size digit buffer
        std::unique_ptr<natural_digit[]> large_digits_;
                                        // Pointer to large digit buffer, if needed

        auto reserve(std::size_t new_digits) -> void;
        auto expand(std::size_t new_digits) -> void;
        auto copy_digits(const natural &v) -> void;
{'fraction_non_alphanumeric': 0.10661661191928672, 'fraction_numerical': 0.006381980290943219, 'mean_word_length': 2.2828096118299444, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1913712', 'n_tokens_mistral': 3090, 'n_tokens_neox': 2966, 'n_words': 974}