Newton Dynamics  4.00
ndGoogol.h
1 /* Copyright (c) <2003-2022> <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 __NDGoogol__
23 #define __NDGoogol__
24 
25 #include "ndCoreStdafx.h"
26 #include "ndTypes.h"
27 #include "ndMemory.h"
28 #include "ndArray.h"
29 #include "ndVector.h"
30 #include "ndClassAlloc.h"
31 #include "ndTemplateVector.h"
32 
33 
34 //#define ND_GOOGOL_SIZE 16
35 #define ND_GOOGOL_SIZE 4
36 
37 class ndGoogol
38 {
39  public:
40  D_OPERATOR_NEW_AND_DELETE
41 
42  ndGoogol(void);
43  ndGoogol(ndFloat64 value);
44 
45  operator double() const;
46  ndGoogol operator+ (const ndGoogol &A) const;
47  ndGoogol operator- (const ndGoogol &A) const;
48  ndGoogol operator* (const ndGoogol &A) const;
49  ndGoogol operator/ (const ndGoogol &A) const;
50 
51  ndGoogol operator+= (const ndGoogol &A);
52  ndGoogol operator-= (const ndGoogol &A);
53 
54  bool operator> (const ndGoogol &A) const;
55  bool operator>= (const ndGoogol &A) const;
56  bool operator< (const ndGoogol &A) const;
57  bool operator<= (const ndGoogol &A) const;
58  bool operator== (const ndGoogol &A) const;
59  bool operator!= (const ndGoogol &A) const;
60 
61  ndGoogol Abs () const;
62  ndGoogol Sqrt () const;
63  ndGoogol InvSqrt () const;
64  ndGoogol Floor () const;
65 
66  void Trace () const;
67  void ToString (char* const string) const;
68 
69  private:
70  void InitFloatFloat (ndFloat64 value);
71  void NegateMantissa (ndUnsigned64* const mantissa) const;
72  void CopySignedMantissa (ndUnsigned64* const mantissa) const;
73  ndInt32 NormalizeMantissa (ndUnsigned64* const mantissa) const;
74  ndUnsigned64 CheckCarrier (ndUnsigned64 a, ndUnsigned64 b) const;
75  void ShiftRightMantissa (ndUnsigned64* const mantissa, ndInt32 bits) const;
76 
77  ndInt32 LeadingZeros (ndUnsigned64 a) const;
78  void ExtendeMultiply (ndUnsigned64 a, ndUnsigned64 b, ndUnsigned64& high, ndUnsigned64& low) const;
79  void ScaleMantissa (ndUnsigned64* const out, ndUnsigned64 scale) const;
80 
81  ndInt32 m_sign;
82  ndInt32 m_exponent;
83  ndUnsigned64 m_mantissa[ND_GOOGOL_SIZE];
84 
85  public:
86  D_CORE_API static ndGoogol m_zero;
87  D_CORE_API static ndGoogol m_one;
88  D_CORE_API static ndGoogol m_two;
89  D_CORE_API static ndGoogol m_three;
90  D_CORE_API static ndGoogol m_half;
91 };
92 
93 class ndHugeVector: public ndTemplateVector<ndGoogol>
94 {
95  public:
96  ndHugeVector ()
98  {
99  }
100 
101  ndHugeVector (const ndBigVector& a)
102  :ndTemplateVector<ndGoogol>(ndGoogol (a.m_x), ndGoogol (a.m_y), ndGoogol (a.m_z), ndGoogol (a.m_w))
103  {
104  }
105 
108  {
109  }
110 
111  ndHugeVector (ndFloat64 x, ndFloat64 y, ndFloat64 z, ndFloat64 w)
112  :ndTemplateVector<ndGoogol>(x, y, z, w)
113  {
114  }
115 
116  ndHugeVector(const ndGoogol& x, const ndGoogol& y, const ndGoogol& z, const ndGoogol& w)
117  :ndTemplateVector<ndGoogol>(x, y, z, w)
118  {
119  }
120 
121  ndGoogol EvaluePlane (const ndHugeVector& point) const
122  {
123  //return (point % (*this)) + m_w;
124  return DotProduct(point).GetScalar();
125  }
126 
127 #ifdef _DEBUG
128  void Trace () const
129  {
130  m_x.Trace();
131  m_y.Trace();
132  m_z.Trace();
133  m_w.Trace();
134  ndAssert(0);
135 // dTrace (("\n"));
136  }
137 #endif
138 };
139 
140 
141 #endif
ndHugeVector
Definition: ndGoogol.h:94
ndTemplateVector
Definition: ndTemplateVector.h:31
ndGoogol
Definition: ndGoogol.h:38
ndBigVector
Definition: ndVectorArmNeon.h:463