<commit_before>// Filename: nearly_zero.h
// Created by:  drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// <EMAIL> .
//
////////////////////////////////////////////////////////////////////

#ifndef NEARLY_ZERO_H
#define NEARLY_ZERO_H


// The following two functions are defined just to make the
// NEARLY_ZERO() macro work.  They each return a suitable nearly-zero
// value for their corresponding numeric type.
INLINE_LINMATH double
get_nearly_zero_value(double) {
  return 1.0e-12;
}

INLINE_LINMATH float
get_nearly_zero_value(float) {
  return 1.0e-6f;
}


// IS_THRESHOLD_ZERO(value, threshold) returns true if the value is
// within threshold of zero.
#define IS_THRESHOLD_ZERO(value, threshold) \
  ((value) < (threshold) && (value) > -(threshold))

// IS_THRESHOLD_EQUAL(value1, value2, threshold) returns true if the
// two values are within threshold of each other.
#define IS_THRESHOLD_EQUAL(value1, value2, threshold) \
  (IS_THRESHOLD_ZERO((value1) - (value2), threshold))


// NEARLY_ZERO(float) returns a number that is considered to be so
// close to zero as not to matter for a float.  NEARLY_ZERO(double)
// returns a similar, smaller number for a double.
#define NEARLY_ZERO(FLOATTYPE) (get_nearly_zero_value((FLOATTYPE)0))

// IS_NEARLY_ZERO(value) returns true if the value is very close to
// zero.
#define IS_NEARLY_ZERO(value) \
  (IS_THRESHOLD_ZERO(value, get_nearly_zero_value(value)))

// IS_NEARLY_EQUAL(value1, value2) returns true if the two values are
// very close to each other.
#define IS_NEARLY_EQUAL(value1, value2) \
   IS_NEARLY_ZERO((value1) - (value2))


// MAYBE_ZERO(value) returns 0 if the value is nearly zero, and the
// value itself otherwise.
#define MAYBE_ZERO(value) \
  (IS_NEARLY_ZERO(value) ? 0.0 : value)


#endif<commit_msg>support transitive principle in nearly_equal<commit_after>// Filename: nearly_zero.h
// Created by:  drose (08Mar00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// <EMAIL> .
//
////////////////////////////////////////////////////////////////////

#ifndef NEARLY_ZERO_H
#define NEARLY_ZERO_H


// The following two functions are defined just to make the
// NEARLY_ZERO() macro work.  They each return a suitable nearly-zero
// value for their corresponding numeric type.
INLINE_LINMATH double
get_nearly_zero_value(double) {
  return 1.0e-12;
}

INLINE_LINMATH float
get_nearly_zero_value(float) {
  return 1.0e-6f;
}


// IS_THRESHOLD_ZERO(value, threshold) returns true if the value is
// within threshold of zero.
#define IS_THRESHOLD_ZERO(value, threshold) \
  ((value) < (threshold) && (value) > -(threshold))

// IS_THRESHOLD_EQUAL(value1, value2, threshold) returns true if the
// two values are within threshold of each other.  The transitive
// principle is guaranteed: IS_THRESHOLD_EQUAL(a, b, t) &&
// IS_THRESHOLD_EQUAL(b, c, t) implies IS_THRESHOLD_EQUAL(a, c, t).

// We could define this via IS_THRESHOLD_ZERO(a - b, t) that wouldn't
// guarantee the transitive principle, stated above.  So we need a
// more complex definition that rounds these to the nearest multiples
// of threshold before comparing them.
#define IS_THRESHOLD_EQUAL(value1, value2, threshold) \
  (cfloor(value1 / threshold + 0.5f) == cfloor(value2 / threshold + 0.5f))


// NEARLY_ZERO(float) returns a number that is considered to be so
// close to zero as not to matter for a float.  NEARLY_ZERO(double)
// returns a similar, smaller number for a double.
#define NEARLY_ZERO(FLOATTYPE) (get_nearly_zero_value((FLOATTYPE)0))

// IS_NEARLY_ZERO(value) returns true if the value is very close to
// zero.
#define IS_NEARLY_ZERO(value) \
  (IS_THRESHOLD_ZERO(value, get_nearly_zero_value(value)))

// IS_NEARLY_EQUAL(value1, value2) returns true if the two values are
// very close to each other.
#define IS_NEARLY_EQUAL(value1, value2) \
   (IS_THRESHOLD_EQUAL(value1, value2, get_nearly_zero_value(value1)))


// MAYBE_ZERO(value) returns 0 if the value is nearly zero, and the
// value itself otherwise.
#define MAYBE_ZERO(value) \
  (IS_NEARLY_ZERO(value) ? 0.0 : (value))


#endif
{'fraction_non_alphanumeric': 0.1509090909090909, 'fraction_numerical': 0.014747474747474747, 'mean_word_length': 3.136173767752715, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1186951', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1585, 'n_words': 531}