<commit_before>// Copyright Published at floating-point-gui.de
// under the Creative Commons Attribution License (BY)
// http://creativecommons.org/licenses/by/3.0/

package math

//------------------------------------------------------------------------------

// Returns true if the relative error between a and b is less than epsilon.
//
// Handles special cases: zero, infinites, denormals.
func NearlyEqual(a, b float32, epsilon float32) bool {
	// Source: http://floating-point-gui.de/errors/comparison/

	absA := a
	if absA < 0 {
		absA = -absA
	}
	absB := b
	if absB < 0 {
		absB = -absB
	}
	diff := a - b
	if diff < 0 {
		diff = -diff
	}

	if a == b {
		// Shortcut, handles infinities.
		return true
	} else if a == 0 || b == 0 || diff < SmallestNormalFloat32 {
		// a or b is zero or both are extremely close to it.
		// Relative error is less meaningful here.
		return diff < (epsilon * SmallestNormalFloat32)
	} else {
		// Use relative error.
		return diff/(absA+absB) < epsilon
	}
}

//------------------------------------------------------------------------------<commit_msg>Use Abs.<commit_after>// Copyright Published at floating-point-gui.de
// under the Creative Commons Attribution License (BY)
// http://creativecommons.org/licenses/by/3.0/

package math

//------------------------------------------------------------------------------

// Returns true if the relative error between a and b is less than epsilon.
//
// Handles special cases: zero, infinites, denormals.
func NearlyEqual(a, b float32, epsilon float32) bool {
	// Source: http://floating-point-gui.de/errors/comparison/

	absA := Abs(a)
	absB := Abs(b)
	diff := Abs(a - b)

	if a == b {
		// Shortcut, handles infinities.
		return true
	} else if a == 0 || b == 0 || diff < SmallestNormalFloat32 {
		// a or b is zero or both are extremely close to it.
		// Relative error is less meaningful here.
		return diff < (epsilon * SmallestNormalFloat32)
	} else {
		// Use relative error.
		return diff/(absA+absB) < epsilon
	}
}

//------------------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.2570473005255614, 'fraction_numerical': 0.012900143334925944, 'mean_word_length': 1.7019354838709677, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 3, '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': '3666827', 'n_tokens_mistral': 651, 'n_tokens_neox': 598, 'n_words': 208}