<commit_before>#pragma once
// posit_32_2.hpp: specialized 32-bit posit using fast compute specialized for posit<32,2>
//
// Copyright (C) 2017-2019 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

namespace sw {
	namespace unum {

// set the fast specialization variable to indicate that we are running a special template specialization
#ifndef POSIT_FAST_POSIT_32_2
  #if defined(POSIT_FAST_SPECIALIZATION)
    #define POSIT_FAST_POSIT_32_2 1
  #else
    #define POSIT_FAST_POSIT_32_2 0
  #endif
#endif

#if POSIT_FAST_POSIT_32_2

	// fast specialized posit<32,2>
	template<>
	class posit<NBITS_IS_32, ES_IS_2> {
	public:
		static constexpr size_t nbits = NBITS_IS_32;
		static constexpr size_t es = ES_IS_2;
		static constexpr size_t sbits = 1;
		static constexpr size_t rbits = nbits - sbits;
		static constexpr size_t ebits = es;
		static constexpr size_t fbits = nbits - 3;
		static constexpr size_t fhbits = fbits + 1;
		static constexpr uint8_t index_shift = 4;

		posit() { _bits = 0; }
		posit(const posit&) = default;
		posit(posit&&) = default;
		posit& operator=(const posit&) = default;
		posit& operator=(posit&&) = default;

		// initializers for native types
		posit(const signed char initial_value)        { *this = initial_value; }
		posit(const short initial_value)              { *this = initial_value; }
		posit(const int initial_value)                { *this = initial_value; }
		posit(const long initial_value)               { *this = initial_value; }
		posit(const long long initial_value)          { *this = initial_value; }
		posit(const char initial_value)               { *this = initial_value; }
		posit(const unsigned short initial_value)     { *this = initial_value; }
		posit(const unsigned int initial_value)       { *this = initial_value; }
		posit(const unsigned long initial_value)      { *this = initial_value; }
		posit(const unsigned long long initial_value) { *this = initial_value; }
		posit(const float initial_value)              { *this = initial_value; }
		posit(const double initial_value)             { *this = initial_value; }
		posit(const long double initial_value)        { *this = initial_value; }

		// assignment operators for native types
		posit& operator=(const signed char rhs)       { return operator=((long)(rhs)); }
		posit& operator=(const short rhs)             { return operator=((long)(rhs)); }
		posit& operator=(const int rhs)               { return operator=((long)(rhs)); }
		posit& operator=(const long rhs) {
			// special case for speed as this is a common initialization
			if (rhs == 0) {
				_bits = 0x0;
				return *this;
			}
			constexpr uint32_t sign_mask = 0x8000'0000;
			bool sign = bool(rhs & sign_mask);
			int32_t v = sign ? -rhs : rhs; // project to positive side of the projective reals
			uint32_t raw;
			if (v == sign_mask) { // +-maxpos, 0x8000'0000 is special in int32 arithmetic as it is its own negation
				raw = sign_mask;
			}
			else if (v > 0xFFFFFBFF) { // 4294966271
				raw = 0x7FC0'0000;     // 4294967296
			}
			else if (v < 0x2) {        // 0 and 1
				raw = (v << 30);
			}
			else {				
				int8_t m = 31;
				uint32_t fraction_bits = v;
				while (!(fraction_bits & sign_mask)) {
					--m;
					fraction_bits <<= 1;
				}
				int8_t k = (m >> 2);
				uint32_t exponent_bits = (m & 0x3) << (27 - k);
				fraction_bits = (fraction_bits ^ sign_mask);<commit_msg>remove type mismatch in masking of long value in assignment<commit_after>#pragma once
// posit_32_2.hpp: specialized 32-bit posit using fast compute specialized for posit<32,2>
//
// Copyright (C) 2017-2019 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

namespace sw {
	namespace unum {

// set the fast specialization variable to indicate that we are running a special template specialization
#ifndef POSIT_FAST_POSIT_32_2
  #if defined(POSIT_FAST_SPECIALIZATION)
    #define POSIT_FAST_POSIT_32_2 1
  #else
    #define POSIT_FAST_POSIT_32_2 0
  #endif
#endif

#if POSIT_FAST_POSIT_32_2

	// fast specialized posit<32,2>
	template<>
	class posit<NBITS_IS_32, ES_IS_2> {
	public:
		static constexpr size_t nbits = NBITS_IS_32;
		static constexpr size_t es = ES_IS_2;
		static constexpr size_t sbits = 1;
		static constexpr size_t rbits = nbits - sbits;
		static constexpr size_t ebits = es;
		static constexpr size_t fbits = nbits - 3;
		static constexpr size_t fhbits = fbits + 1;
		static constexpr uint8_t index_shift = 4;

		posit() { _bits = 0; }
		posit(const posit&) = default;
		posit(posit&&) = default;
		posit& operator=(const posit&) = default;
		posit& operator=(posit&&) = default;

		// initializers for native types
		posit(const signed char initial_value)        { *this = initial_value; }
		posit(const short initial_value)              { *this = initial_value; }
		posit(const int initial_value)                { *this = initial_value; }
		posit(const long initial_value)               { *this = initial_value; }
		posit(const long long initial_value)          { *this = initial_value; }
		posit(const char initial_value)               { *this = initial_value; }
		posit(const unsigned short initial_value)     { *this = initial_value; }
		posit(const unsigned int initial_value)       { *this = initial_value; }
		posit(const unsigned long initial_value)      { *this = initial_value; }
		posit(const unsigned long long initial_value) { *this = initial_value; }
		posit(const float initial_value)              { *this = initial_value; }
		posit(const double initial_value)             { *this = initial_value; }
		posit(const long double initial_value)        { *this = initial_value; }

		// assignment operators for native types
		posit& operator=(const signed char rhs)       { return operator=((long)(rhs)); }
		posit& operator=(const short rhs)             { return operator=((long)(rhs)); }
		posit& operator=(const int rhs)               { return operator=((long)(rhs)); }
		posit& operator=(const long rhs) {
			// special case for speed as this is a common initialization
			if (rhs == 0) {
				_bits = 0x0;
				return *this;
			}
			constexpr uint32_t sign_mask = 0x8000'0000;
			bool sign = bool(rhs & sign_mask);
			uint32_t v = sign ? -rhs : rhs; // project to positive side of the projective reals
			uint32_t raw;
			if (v == sign_mask) { // +-maxpos, 0x8000'0000 is special in int32 arithmetic as it is its own negation
				raw = sign_mask;
			}
			else if (v > 0xFFFFFBFF) { // 4294966271
				raw = 0x7FC0'0000;     // 4294967296
			}
			else if (v < 0x2) {        // 0 and 1
				raw = (v << 30);
			}
			else {				
				int8_t m = 31;
				uint32_t fraction_bits = v;
				while (!(fraction_bits & sign_mask)) {
					--m;
					fraction_bits <<= 1;
				}
				int8_t k = (m >> 2);
				uint32_t exponent_bits = (m & 0x3) << (27 - k);
				fraction_bits = (fraction_bits ^ sign_mask);
{'fraction_non_alphanumeric': 0.10153449017639467, 'fraction_numerical': 0.034992112433672735, 'mean_word_length': 3.03121387283237, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 17, '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': '104672', 'n_tokens_mistral': 2678, 'n_tokens_neox': 2267, 'n_words': 694}