<commit_before>//
// Created by Timo on 18.04.2016.
//

#ifndef CPP_BHT_SOSE16_A02_FIXED_POINT_H
#define CPP_BHT_SOSE16_A02_FIXED_POINT_H


#include <cstdint>
#include <cmath>

// numbertrait for always using the (s)mallest (p)ossible (d)atatype => spd
template<int bitSize>
struct use_spd{ using impl_type = int ; using doubled_impl_type = int64_t; };

template<>
struct use_spd <8> { using type = int8_t; };

template<>
struct use_spd <16> { using type = int16_t; };

template<>
struct use_spd <32> { using type = int32_t; };

template<>
struct use_spd <64> { using type = int64_t; };

template <int8_t Decimal, int8_t Fraction>
class fixed_point {
    using impl_type = typename use_spd<Decimal + Fraction>::type;
    using doubled_impl_type = typename  use_spd<2*(Decimal + Fraction)>::type;
public:
    fixed_point(float x) {
        q = x * std::pow(2, Fraction);
    }

    explicit operator int() const {
        return q / std::pow(2, Fraction);
    }

    explicit operator float() const {
        return q / std::pow(2, Fraction);
    }

    template <int8_t DecimalF, int8_t FractionF>
    friend fixed_point<DecimalF, FractionF> abs(fixed_point<DecimalF, FractionF> fixedPoint) {
        if (fixedPoint >= 0) {
            return fixedPoint;
        } else {
            return -fixedPoint;
        }
    };

    fixed_point operator+() const {
        fixed_point temp(*this);
        return temp;
    }

    fixed_point operator-() const {
        fixed_point temp(*this);
        temp.q = -temp.q;
        return temp;
    }

    fixed_point operator+(fixed_point rhs) const {
        fixed_point<Decimal, Fraction> temp(*this);
        temp.q += rhs.q;
        return temp;
    }

    fixed_point operator-(fixed_point rhs) const {
        fixed_point<Decimal, Fraction> temp = *this;
        temp.q -= rhs.q;
        return temp;
    }

    fixed_point operator*(fixed_point rhs) const {
        doubled_impl_type temp = (((doubled_impl_type)q) * ((doubled_impl_type)rhs.q)) >> Fraction;
        fixed_point<Decimal, Fraction> fp((impl_type)temp);
        return fp;
    }

    fixed_point operator/(fixed_point rhs) const {
        fixed_point<Decimal, Fraction> tempFixed(*this);

        int32_t result;
        int64_t temp;

        temp = (int64_t) q << 16;

        if ((temp >= 0 && rhs.q >= 0) || (temp < 0 && rhs.q < 0)) {
            temp += rhs.q / 2;
        } else {
            temp -= rhs.q / 2;
        }

        result = (int32_t)(temp / rhs.q);

        tempFixed.q = result;

        return tempFixed;
    }

    fixed_point &operator+=(fixed_point rhs) {
        q += rhs.q;
        return *this;
    }

    fixed_point &operator-=(fixed_point rhs) {
        q -= rhs.q;
        return *this;
    }

    fixed_point &operator*=(fixed_point rhs) {
        q = ((int64_t)q * (int64_t)rhs.q) >> 16;
        return *this;
    }

    fixed_point &operator/=(fixed_point rhs) {
        int32_t result;
        int64_t temp;

        temp = (int64_t) q << 16;

        if ((temp >= 0 && rhs.q >= 0) || (temp < 0 && rhs.q < 0)) {
            temp += rhs.q / 2;
        } else {
            temp -= rhs.q / 2;
        }

        result = (int32_t)(temp / rhs.q);

        q = result;

        return *this;
    }

    bool operator==(fixed_point rhs) const {
        return q == rhs.q;
    }
    bool operator!=(fixed_point rhs) const {
        return q != rhs.q;
    }
    bool operator<(fixed_point rhs) const {
        return q < rhs.q;
    }
    bool operator>(fixed_point rhs) const {
        return q > rhs.q;
    }
    bool operator<=(fixed_point rhs) const {
        return q <= rhs.q;
    }
    bool operator>=(fixed_point rhs) const {
        return q >= rhs.q;
    }

    fixed_point& operator++() {
        q += std::pow(2, 16);
        return *this;
    }

    fixed_point operator++(int) {
        fixed_point<Decimal, Fraction> temp = *this;
        q += std::pow(2, 16);
        return temp;
    }

    fixed_point& operator--() {
        q -= std::pow(2, 16);
        return *this;
    }
    fixed_point operator--(int) {
        fixed_point<Decimal, Fraction> temp = *this;
        q -= std::pow(2, 16);
        return temp;
    }

private:
    std::int32_t q;<commit_msg>fixed_point: - Replaced ints with type traits<commit_after>//
// Created by Timo on 18.04.2016.
//

#ifndef CPP_BHT_SOSE16_A02_FIXED_POINT_H
#define CPP_BHT_SOSE16_A02_FIXED_POINT_H


#include <cstdint>
#include <cmath>

// numbertrait for always using the (s)mallest (p)ossible (d)atatype => spd
template<int bitSize>
struct use_spd{ using impl_type = int ; using doubled_impl_type = int64_t; };

template<>
struct use_spd <8> { using type = int8_t; };

template<>
struct use_spd <16> { using type = int16_t; };

template<>
struct use_spd <32> { using type = int32_t; };

template<>
struct use_spd <64> { using type = int64_t; };

template <int8_t Decimal, int8_t Fraction>
class fixed_point {
    using impl_type = typename use_spd<Decimal + Fraction>::type;
    using doubled_impl_type = typename  use_spd<2*(Decimal + Fraction)>::type;
public:
    fixed_point(float x) {
        q = x * std::pow(2, Fraction);
    }

    explicit operator int() const {
        return q / std::pow(2, Fraction);
    }

    explicit operator float() const {
        return q / std::pow(2, Fraction);
    }

    template <int8_t DecimalF, int8_t FractionF>
    friend fixed_point<DecimalF, FractionF> abs(fixed_point<DecimalF, FractionF> fixedPoint) {
        if (fixedPoint >= 0) {
            return fixedPoint;
        } else {
            return -fixedPoint;
        }
    };

    fixed_point operator+() const {
        fixed_point temp(*this);
        return temp;
    }

    fixed_point operator-() const {
        fixed_point temp(*this);
        temp.q = -temp.q;
        return temp;
    }

    fixed_point operator+(fixed_point rhs) const {
        fixed_point<Decimal, Fraction> temp(*this);
        temp.q += rhs.q;
        return temp;
    }

    fixed_point operator-(fixed_point rhs) const {
        fixed_point<Decimal, Fraction> temp = *this;
        temp.q -= rhs.q;
        return temp;
    }

    fixed_point operator*(fixed_point rhs) const {
//        doubled_impl_type temp = (((doubled_impl_type)q) * ((doubled_impl_type)rhs.q)) >> Fraction;
//        fixed_point<Decimal, Fraction> fp((impl_type)temp);
//        return fp;

        fixed_point<Decimal, Fraction> tempFixed(*this);

        impl_type result;
        doubled_impl_type temp;

        temp = (doubled_impl_type) q * (doubled_impl_type) rhs.q;
        temp += Decimal;

        result = (impl_type) temp;

        tempFixed.q = result;

        return tempFixed;
    }

    fixed_point operator/(fixed_point rhs) const {
        fixed_point<Decimal, Fraction> tempFixed(*this);

        impl_type result;
        doubled_impl_type temp;

        temp = (doubled_impl_type) q << Fraction;

        if ((temp >= 0 && rhs.q >= 0) || (temp < 0 && rhs.q < 0)) {
            temp += rhs.q / 2;
        } else {
            temp -= rhs.q / 2;
        }

        result = (impl_type)(temp / rhs.q);

        tempFixed.q = result;

        return tempFixed;
    }

    fixed_point &operator+=(fixed_point rhs) {
        q += rhs.q;
        return *this;
    }

    fixed_point &operator-=(fixed_point rhs) {
        q -= rhs.q;
        return *this;
    }

    fixed_point &operator*=(fixed_point rhs) {
        doubled_impl_type temp = ((doubled_impl_type)q * (doubled_impl_type)rhs.q) >> Fraction;
        q = (impl_type) temp;
        return *this;
    }

    fixed_point &operator/=(fixed_point rhs) {
        impl_type result;
        doubled_impl_type temp;

        temp = (doubled_impl_type) q << Fraction;

        if ((temp >= 0 && rhs.q >= 0) || (temp < 0 && rhs.q < 0)) {
            temp += rhs.q / 2;
        } else {
            temp -= rhs.q / 2;
        }

        result = (impl_type)(temp / rhs.q);

        q = result;

        return *this;
    }

    bool operator==(fixed_point rhs) const {
        return q == rhs.q;
    }
    bool operator!=(fixed_point rhs) const {
        return q != rhs.q;
    }
    bool operator<(fixed_point rhs) const {
        return q < rhs.q;
    }
    bool operator>(fixed_point rhs) const {
        return q > rhs.q;
    }
    bool operator<=(fixed_point rhs) const {
        return q <= rhs.q;
    }
    bool operator>=(fixed_point rhs) const {
        return q >= rhs.q;
    }

    fixed_point& operator++() {
        q += std::pow(2, 16);
        return *this;
    }

    fixed_point operator++(int) {
        fixed_point<Decimal, Fraction> temp = *this;
        q += std::pow(2, 16);
        return temp;
    }

    fixed_point& operator--() {
        q -= std::pow(2, 16);
        return *this;
    }
    fixed_point operator--(int) {
        fixed_point<Decimal, Fraction> temp = *this;
        q -= std::pow(2, 16);
        return temp;
    }

private:
    impl_type q;
{'fraction_non_alphanumeric': 0.12896714141527418, 'fraction_numerical': 0.017718963777055063, 'mean_word_length': 2.125832457062741, 'pattern_counts': {'":': 0, '<': 74, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4173847', 'n_tokens_mistral': 3158, 'n_tokens_neox': 2990, 'n_words': 727}