GteBSPrecision.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <GTEngineDEF.h>
11 #include <cstdint>
12 #include <limits>
13 
14 // Support for determining the number of bits of precision required to compute
15 // an expression. See the document
16 // http://www.geometrictools.com/Documentation/ArbitraryPrecision.pdf
17 // for an example of how to use this class.
18 
19 namespace gte
20 {
21 
23 {
24 public:
25  // This constructor is used for 'float' or 'double'. The floating-point
26  // inputs for the expressions have no restrictions; that is, the inputs
27  // can be any finite floating-point numbers (normal or subnormal).
28  BSPrecision(bool isFloat, bool forBSNumber);
29 
30  // If you know that your inputs are limited in magnitude, use this
31  // constructor. For example, if you know that your inputs x satisfy
32  // |x| <= 8, you can specify maxExponent of 3. The minimum power will
33  // still be that for the smallest positive subnormal.
34  BSPrecision(bool isFloat, int32_t maxExponent, bool forBSNumber);
35 
36  // You must use this constructor carefully based on knowledge of your
37  // expressions. For example, if you know that your inputs are 'float'
38  // and in the interval [1,2), you would choose 24 for the number of bits
39  // of precision, a minimum biased exponent of -23 because the largest
40  // 'float' smaller than 2 is 1.1^{23}*2^0 = 1^{24}*2^{-23}, and a maximum
41  // exponent of 0. These numbers work to determine bits of precision to
42  // compute x*y+z*w. However, if you then compute an expression such as
43  // x-y for x and y in [1,2) and multiply by powers of 1/2, the bit
44  // counting will not be correct because the results can be subnormals
45  // where the minimum biased exponent is -149, not -23.
46  BSPrecision(int32_t numBits, int32_t minBiasedExponent,
47  int32_t maxExponent, bool forBSNumber);
48 
49  // Member access.
50  int32_t GetNumWords() const;
51  int32_t GetNumBits() const;
52  int32_t GetMinBiasedExponent() const;
53  int32_t GetMinExponent() const;
54  int32_t GetMaxExponent() const;
55 
56  // Support for determining the number of bits of precision required to
57  // compute an expression using BSNumber or BSRational.
59  BSPrecision operator+(BSPrecision const& precision);
60  BSPrecision operator-(BSPrecision const& precision);
61 
62  // Support for determining the number of bits of precision required to
63  // compute a BSRational expression (operations not relevant for BSNumber).
64  BSPrecision operator/(BSPrecision const& precision);
65  BSPrecision operator==(BSPrecision const& precision);
66  BSPrecision operator!=(BSPrecision const& precision);
67  BSPrecision operator< (BSPrecision const& precision);
68  BSPrecision operator<=(BSPrecision const& precision);
69  BSPrecision operator> (BSPrecision const& precision);
70  BSPrecision operator>=(BSPrecision const& precision);
71 
72 private:
75 };
76 
77 }
BSPrecision operator/(BSPrecision const &precision)
BSPrecision operator<(BSPrecision const &precision)
BSPrecision operator*(BSPrecision const &precision)
BSPrecision operator<=(BSPrecision const &precision)
int32_t GetMaxExponent() const
BSPrecision operator+(BSPrecision const &precision)
BSPrecision operator-(BSPrecision const &precision)
BSPrecision operator==(BSPrecision const &precision)
int32_t GetNumBits() const
int32_t GetNumWords() const
GLenum GLint GLint * precision
Definition: glcorearb.h:1920
int32_t GetMinExponent() const
BSPrecision operator>(BSPrecision const &precision)
int32_t GetMinBiasedExponent() const
int32_t mMinBiasedExponent
BSPrecision(bool isFloat, bool forBSNumber)
BSPrecision operator!=(BSPrecision const &precision)
BSPrecision operator>=(BSPrecision const &precision)


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59