Newton Dynamics  4.00
dGoogol.h
1 /* Copyright (c) <2003-2019> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __dGoogol__
23 #define __dGoogol__
24 
25 #include "dCoreStdafx.h"
26 #include "dTypes.h"
27 #include "dMemory.h"
28 #include "dArray.h"
29 #include "dVector.h"
30 #include "dClassAlloc.h"
31 #include "dTemplateVector.h"
32 
33 
34 //#define DG_GOOGOL_SIZE 16
35 #define DG_GOOGOL_SIZE 4
36 
37 class dGoogol: public dClassAlloc
38 {
39  public:
40  dGoogol(void);
41  dGoogol(dFloat64 value);
42 
43  operator double() const;
44  dGoogol operator+ (const dGoogol &A) const;
45  dGoogol operator- (const dGoogol &A) const;
46  dGoogol operator* (const dGoogol &A) const;
47  dGoogol operator/ (const dGoogol &A) const;
48 
49  dGoogol operator+= (const dGoogol &A);
50  dGoogol operator-= (const dGoogol &A);
51 
52  bool operator> (const dGoogol &A) const;
53  bool operator>= (const dGoogol &A) const;
54  bool operator< (const dGoogol &A) const;
55  bool operator<= (const dGoogol &A) const;
56  bool operator== (const dGoogol &A) const;
57  bool operator!= (const dGoogol &A) const;
58 
59  dGoogol Abs () const;
60  dGoogol Sqrt () const;
61  dGoogol InvSqrt () const;
62  dGoogol Floor () const;
63 
64  void Trace () const;
65  void ToString (char* const string) const;
66 
67  private:
68  void InitFloatFloat (dFloat64 value);
69  void NegateMantissa (dUnsigned64* const mantissa) const;
70  void CopySignedMantissa (dUnsigned64* const mantissa) const;
71  dInt32 NormalizeMantissa (dUnsigned64* const mantissa) const;
72  dUnsigned64 CheckCarrier (dUnsigned64 a, dUnsigned64 b) const;
73  void ShiftRightMantissa (dUnsigned64* const mantissa, dInt32 bits) const;
74 
75  dInt32 LeadingZeros (dUnsigned64 a) const;
76  void ExtendeMultiply (dUnsigned64 a, dUnsigned64 b, dUnsigned64& high, dUnsigned64& low) const;
77  void ScaleMantissa (dUnsigned64* const out, dUnsigned64 scale) const;
78 
79  dInt32 m_sign;
80  dInt32 m_exponent;
81  dUnsigned64 m_mantissa[DG_GOOGOL_SIZE];
82 
83  public:
84  D_CORE_API static dGoogol m_zero;
85  D_CORE_API static dGoogol m_one;
86  D_CORE_API static dGoogol m_two;
87  D_CORE_API static dGoogol m_three;
88  D_CORE_API static dGoogol m_half;
89 };
90 
91 class dHugeVector: public dTemplateVector<dGoogol>
92 {
93  public:
94  dHugeVector ()
96  {
97  }
98 
99  dHugeVector (const dBigVector& a)
100  :dTemplateVector<dGoogol>(dGoogol (a.m_x), dGoogol (a.m_y), dGoogol (a.m_z), dGoogol (a.m_w))
101  {
102  }
103 
106  {
107  }
108 
109  dHugeVector (dFloat64 x, dFloat64 y, dFloat64 z, dFloat64 w)
110  :dTemplateVector<dGoogol>(x, y, z, w)
111  {
112  }
113 
114  dHugeVector(const dGoogol& x, const dGoogol& y, const dGoogol& z, const dGoogol& w)
115  :dTemplateVector<dGoogol>(x, y, z, w)
116  {
117  }
118 
119  dGoogol EvaluePlane (const dHugeVector& point) const
120  {
121  //return (point % (*this)) + m_w;
122  return DotProduct(point).GetScalar();
123  }
124 
125 #ifdef _DEBUG
126  void Trace () const
127  {
128  m_x.Trace();
129  m_y.Trace();
130  m_z.Trace();
131  m_w.Trace();
132  dAssert(0);
133 // dTrace (("\n"));
134  }
135 #endif
136 };
137 
138 
139 #endif
dGoogol
Definition: dGoogol.h:38
dClassAlloc
Base class for providing memory allocation for all other engine classes.
Definition: dClassAlloc.h:29
dBigVector
Definition: dVectorArmNeon.h:1521
dHugeVector
Definition: dGoogol.h:92
dTemplateVector
Definition: dTemplateVector.h:33