<commit_before>/* IntNormal.cpp */

#include "IntNormal.h"

void IntNormal::_bind_methods() {
	ObjectTypeDB::bind_method("normal",&IntNormal::normal);
// 	ObjectTypeDB::bind_method("skew",&BaseNormal::skew);
	ObjectTypeDB::bind_method("generate",&IntNormal::generate);
	ObjectTypeDB::bind_method("getvalue",&IntNormal::getvalue);
	ObjectTypeDB::bind_method("getnext",&IntNormal::getnext);
}

int IntNormal::round(float n) {
	// The purpose of the algorithm is to accurately round floating-point numbers.
	// C++11 has a builtin for this but I'm using C++98 here.
	// Would use C++11 but it doesn't play well with Java via Scons, for me.
	float t = n - floor(n);
	t *= 10;
	if(t > 4 && t < 5) {  // Then we need to look at the next digit!
		t = round(t); // Round the current value of t
	}
	// Implicit else
	if(t >= 5)
		return (int)(floor(n)+1);
	// Implicit else
	return (int)floor(n);	
}

void IntNormal::generate(int count) {
	if(sigma > 0) {
		// TODO Seed, if not using an idiom.

		contents.resize(0);
		for(int i=0; i<count; ++i) {
			contents.push_back(round(dr_boxmuller(mu, sigma)));
		}
	}
}
	<commit_msg>Now handles negative values gracefully.<commit_after>/* IntNormal.cpp */

#include "IntNormal.h"

void IntNormal::_bind_methods() {
	ObjectTypeDB::bind_method("normal",&IntNormal::normal);
// 	ObjectTypeDB::bind_method("skew",&BaseNormal::skew);
	ObjectTypeDB::bind_method("generate",&IntNormal::generate);
	ObjectTypeDB::bind_method("getvalue",&IntNormal::getvalue);
	ObjectTypeDB::bind_method("getnext",&IntNormal::getnext);
}

int IntNormal::round(float n) {
	// The purpose of the algorithm is to accurately round floating-point numbers.
	// C++11 has a builtin for this but I'm using C++98 here.
	// Would use C++11 but it doesn't play well with Java via Scons, for me.
	
	if(n < 0) // If n is negative then flip the sign, recurse, then flip again and return.
		return -round(-n);
	// Implicit else
	
	float t = n - floor(n);
	t *= 10;
	if(t > 4 && t < 5) {  // Then we need to look at the next digit!
		t = round(t); // Round the current value of t
	}
	// Implicit else
	if(t >= 5)
		return (int)(floor(n)+1);
	// Implicit else
	return (int)floor(n);	
}

void IntNormal::generate(int count) {
	if(sigma > 0) {
		contents.resize(0);
		for(int i=0; i<count; ++i) {
			contents.push_back(round(dr_boxmuller(mu, sigma))); // Rounding the boxmuller result.
		}
	}
}
	
{'fraction_non_alphanumeric': 0.16058700209643606, 'fraction_numerical': 0.0129979035639413, 'mean_word_length': 4.255506607929515, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, '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': '4686948', 'n_tokens_mistral': 897, 'n_tokens_neox': 850, 'n_words': 233}