<commit_before>// FloatsVisualiser
//
// Just going through the Wikipedia page for IEEE 754 floats. Thought I'd quickly visualise and test.
// http://en.wikipedia.org/wiki/IEEE_754-1985
// <EMAIL>

#include <bitset>
#include <iostream>
#include <limits>
#include <stdint.h>
#include <tchar.h>

using namespace std;

union SpyFloat
{
	unsigned char mRawDataRep[4];
	uint32_t  mUintDataRep;
	float     mFloatRep;
};

void printFloat(const float f)
{
	SpyFloat spyF;
	spyF.mFloatRep = f;

	cout 
		<< "Float " 
		<< scientific 
		<< f 
		<< endl 
		<< "\traw: " 
		<< hex 
		<< spyF.mUintDataRep 
		<< endl 
		<< "\tbinary (exp bias = 127): " 
		<< static_cast<bitset<32>>(spyF.mUintDataRep) 
		<< endl;
}

void printFloatError(const float f)
{
	cout
		<< "Float value: "
		<< scientific
		<< f
		<< " Max Error: "
		<< f * std::numeric_limits<float>::epsilon()
		<< endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
	cout << "Representation of some common types" << endl;

	// zero
	float zeroFloat = 0.0f;
	printFloat(zeroFloat);

	// INF, -INF
	printFloat(numeric_limits<float>::infinity());
	printFloat(-numeric_limits<float>::infinity());

	// NANs
	printFloat(numeric_limits<float>::quiet_NaN());
	printFloat(numeric_limits<float>::signaling_NaN());

	// DEN, NORM min/max
	printFloat(numeric_limits<float>::denorm_min());
	printFloat(numeric_limits<float>::min());
	printFloat(numeric_limits<float>::max());

	cout << "Error limits for some 2^n types" << endl;

	for (int i = 0; i < 32; ++i)
	{
		const float currentVal = std::powf(2.0f, static_cast<float>(i));
		printFloatError(currentVal);
	}

	// For comparison against the Gamasutra Article:
	// http://www.gamasutra.com/view/feature/130382/visualizing_floats.php
	printFloatError(1.e6f);
	printFloatError(64.e6f);
	printFloatError(std::powf(2.0f, 23.0f));
	printFloatError(std::powf(2.0f, 32.0f));

	// Distance to the sun in km
	printFloatError(149597887.5f);
	
	return 0;
}

<commit_msg>added exploratory rounding demo of error<commit_after>// FloatsVisualiser
//
// Just going through the Wikipedia page for IEEE 754 floats. Thought I'd quickly visualise and test.
// http://en.wikipedia.org/wiki/IEEE_754-1985
// <EMAIL>

#include <bitset>
#include <iostream>
#include <limits>
#include <stdint.h>
#include <tchar.h>

using namespace std;

union SpyFloat
{
	unsigned char mRawDataRep[4];
	uint32_t  mUintDataRep;
	float     mFloatRep;
};

void printFloat(const float f)
{
	SpyFloat spyF;
	spyF.mFloatRep = f;

	cout 
		<< "Float " 
		<< scientific 
		<< f 
		<< endl 
		<< "\traw: " 
		<< hex 
		<< spyF.mUintDataRep 
		<< endl 
		<< "\tbinary (exp bias = 127): " 
		<< static_cast<bitset<32>>(spyF.mUintDataRep) 
		<< endl;
}

void printFloatError(const float f)
{
	cout
		<< "Float value: "
		<< scientific
		<< f
		<< " Max Error: "
		<< f * std::numeric_limits<float>::epsilon()
		<< endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
	cout << "Representation of some common types" << endl;

	// zero
	float zeroFloat = 0.0f;
	printFloat(zeroFloat);

	// INF, -INF
	printFloat(numeric_limits<float>::infinity());
	printFloat(-numeric_limits<float>::infinity());

	// NANs
	printFloat(numeric_limits<float>::quiet_NaN());
	printFloat(numeric_limits<float>::signaling_NaN());

	// DEN, NORM min/max
	printFloat(numeric_limits<float>::denorm_min());
	printFloat(numeric_limits<float>::min());
	printFloat(numeric_limits<float>::max());

	cout << "Error limits for some 2^n types" << endl;

	for (int i = 0; i < 32; ++i)
	{
		const float currentVal = std::powf(2.0f, static_cast<float>(i));
		printFloatError(currentVal);
	}

	// For comparison against the Gamasutra Article:
	// http://www.gamasutra.com/view/feature/130382/visualizing_floats.php
	printFloatError(1.e6f);
	printFloatError(64.e6f);
	printFloatError(std::powf(2.0f, 23.0f));
	printFloatError(std::powf(2.0f, 32.0f));

	// Distance to the sun in km
	printFloatError(149597887.5f);

	// Demonstration of error as worst case
	// Exponent of 144 (2^17)
	// Mantissa of 1 (1.0000001192092896)
	// 131072.02
	// Mantissa of 2 (1.000000238418579)
	// 131072.03
	printFloatError(131072.02f);
	printFloatError(131072.03f);
	
	// Rounded to mantissa of 1?
	printFloat(131072.02f);
	printFloat(131072.0225f);

	// Rounded to mantissa of 2?
	printFloat(131072.025f);
	printFloat(131072.0275f);
	printFloat(131072.03f);

	return 0;
}


{'fraction_non_alphanumeric': 0.15850011502185415, 'fraction_numerical': 0.05429031515988038, 'mean_word_length': 4.151658767772512, 'pattern_counts': {'":': 0, '<': 123, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7133588', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1626, 'n_words': 346}