source: NonGTP/FCollada/FMath/FMFloat.h @ 964

Revision 964, 2.1 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*
2        Copyright (C) 2005-2006 Feeling Software Inc.
3        MIT License: http://www.opensource.org/licenses/mit-license.php
4*/
5
6/**
7        @file FMFloat.h
8        The file containing functions and constants for floating point values.
9 */
10
11#ifdef WIN32
12#include <float.h>
13#endif
14
15/** The default tolerance for double-sized floating-point comparison functions. */
16#define DBL_TOLERANCE 0.0001
17/** The default tolerance for single-sized floating-point comparison functions. */
18#define FLT_TOLERANCE 0.0001f
19
20/** A dynamically-sized array of double-sized floating-point values. */
21typedef vector<double> DoubleList;
22
23/** A dynamically-sized array of floating-point values. */
24typedef vector<float> FloatList;
25
26/** Returns whether two floating-point values are equivalent within a given tolerance.
27        @param f1 A first floating-point value.
28        @param f2 A second floating-point value. */
29inline bool IsEquivalent(float f1, float f2) { return f1 - f2 < FLT_TOLERANCE && f2 - f1 < FLT_TOLERANCE; }
30
31/** Returns whether two floating-point values are equivalent within a given tolerance.
32        @param f1 A first floating-point value.
33        @param f2 A second floating-point value.
34        @param tolerance The tolerance in which to accept the two floating-point values as equivalent. */
35inline bool IsEquivalent(float f1, float f2, float tolerance) { return f1 - f2 < tolerance && f2 - f1 < tolerance; }
36
37/** Returns whether two double-sized floating-point values are equivalent.
38        @param f1 A first double-sized floating-point value.
39        @param f2 A second double-sized floating-point value. */
40inline bool IsEquivalent(double f1, double f2) { return f1 - f2 < DBL_TOLERANCE && f2 - f1 < DBL_TOLERANCE; }
41
42/** Returns whether two double-sized floating-point values are equivalent within a given tolerance.
43        @param f1 A first double-sized floating-point value.
44        @param f2 A second double-sized floating-point value.
45        @param tolerance The tolerance in which to accept the two double-sized floating-point values as equivalent. */
46inline bool IsEquivalent(double f1, double f2, double tolerance) { return f1 - f2 < tolerance && f2 - f1 < tolerance; }
Note: See TracBrowser for help on using the repository browser.