My Project: dynamics.mod/NewtonDynamics/source/core/dgGoogol.h Source File

My Project

dgGoogol.h
Go to the documentation of this file.
1 /* Copyright (c) <2003-2011> <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 __dgGoogol__
23 #define __dgGoogol__
24
25
26 #include "dgStdafx.h"
27 #include "dgMemory.h"
28 #include "dgArray.h"
29 #include "dgVector.h"
30
31 #define _IMPLEMENT_USING_INTEGER_ARITHMETIC_
32
33 //#define DG_GOOGOL_SIZE 16
34 #define DG_GOOGOL_SIZE 4
35
36 class dgGoogol
37 {
38 public:
39 dgGoogol(void);
40 dgGoogol(dgFloat64 value);
41
42 operator double() const;
43 dgGoogol operator+ (const dgGoogol &A) const;
44 dgGoogol operator- (const dgGoogol &A) const;
45 dgGoogol operator* (const dgGoogol &A) const;
46 dgGoogol operator/ (const dgGoogol &A) const;
47
48 dgGoogol operator+= (const dgGoogol &A);
49 dgGoogol operator-= (const dgGoogol &A);
50
51 bool operator> (const dgGoogol &A) const;
52 bool operator>= (const dgGoogol &A) const;
53 bool operator< (const dgGoogol &A) const;
54 bool operator<= (const dgGoogol &A) const;
55 bool operator== (const dgGoogol &A) const;
56 bool operator!= (const dgGoogol &A) const;
57
58 dgGoogol Abs () const;
59 dgGoogol Sqrt () const;
60 dgGoogol InvSqrt () const;
61 dgGoogol Floor () const;
62
63 void Trace () const;
64 void ToString (char* const string) const;
65
66
67 private:
68 void InitFloatFloat (dgFloat64 value);
69 void NegateMantissa (dgUnsigned64* const mantissa) const;
70 void CopySignedMantissa (dgUnsigned64* const mantissa) const;
71 dgInt32 NormalizeMantissa (dgUnsigned64* const mantissa) const;
72 dgUnsigned64 CheckCarrier (dgUnsigned64 a, dgUnsigned64 b) const;
73 void ShiftRightMantissa (dgUnsigned64* const mantissa, dgInt32 bits) const;
74
75 dgInt32 LeadingZeros (dgUnsigned64 a) const;
76 void ExtendeMultiply (dgUnsigned64 a, dgUnsigned64 b, dgUnsigned64& high, dgUnsigned64& low) const;
77 void ScaleMantissa (dgUnsigned64* const out, dgUnsigned64 scale) const;
78
79 #ifdef _IMPLEMENT_USING_INTEGER_ARITHMETIC_
80 dgInt32 m_sign;
81 dgInt32 m_exponent;
82 dgUnsigned64 m_mantissa[DG_GOOGOL_SIZE];
83 #else
84 dgFloat64 m_value;
85 #endif
86
87
88 public:
89 static dgGoogol m_zero;
90 static dgGoogol m_one;
91 static dgGoogol m_two;
92 static dgGoogol m_three;
93 static dgGoogol m_half;
94 };
95
96
97 class dgHugeVector: public dgTemplateVector<dgGoogol>
98 {
99 public:
100 dgHugeVector ()
101 :dgTemplateVector<dgGoogol>()
102 {
103 }
104
105 dgHugeVector (const dgBigVector& a)
106 :dgTemplateVector<dgGoogol>(dgGoogol (a.m_x), dgGoogol (a.m_y), dgGoogol (a.m_z), dgGoogol (a.m_w))
107 {
108 }
109
110 dgHugeVector (const dgTemplateVector<dgGoogol>& a)
111 :dgTemplateVector<dgGoogol>(a)
112 {
113 }
114
115 dgHugeVector (dgFloat64 x, dgFloat64 y, dgFloat64 z, dgFloat64 w)
116 :dgTemplateVector<dgGoogol>(x, y, z, w)
117 {
118 }
119
120 dgGoogol EvaluePlane (const dgHugeVector& point) const
121 {
122 return (point % (*this)) + m_w;
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 dgTrace (("\n"));
133 }
134 #endif
135 };
136
137
138 #endif
dgHugeVector
Definition: dgGoogol.h:97
dgUnsigned64
unsigned long long dgUnsigned64
Definition: dgTypes.h:223
dgMemory.h
dgGoogol::Sqrt
dgGoogol Sqrt() const
Definition: dgGoogol.cpp:279
dgInt32
int dgInt32
Definition: dgTypes.h:218
dgHugeVector::dgHugeVector
dgHugeVector(dgFloat64 x, dgFloat64 y, dgFloat64 z, dgFloat64 w)
Definition: dgGoogol.h:115
dgTemplateVector
Definition: dgVector.h:36
dgGoogol::operator*
dgGoogol operator*(const dgGoogol &A) const
Definition: dgGoogol.cpp:162
dgGoogol::m_three
static dgGoogol m_three
Definition: dgGoogol.h:92
dgTrace
#define dgTrace(x)
Definition: dgDebug.h:36
dgHugeVector::dgHugeVector
dgHugeVector(const dgBigVector &a)
Definition: dgGoogol.h:105
dgGoogol::operator<=
bool operator<=(const dgGoogol &A) const
Definition: dgGoogol.cpp:555
dgGoogol::ToString
void ToString(char *const string) const
Definition: dgGoogol.cpp:284
dgGoogol::m_half
static dgGoogol m_half
Definition: dgGoogol.h:93
dgHugeVector::EvaluePlane
dgGoogol EvaluePlane(const dgHugeVector &point) const
Definition: dgGoogol.h:120
dgFloat64
double dgFloat64
Definition: dgTypes.h:224
dgVector.h
dgGoogol::operator-
dgGoogol operator-(const dgGoogol &A) const
Definition: dgGoogol.cpp:133
dgGoogol::Floor
dgGoogol Floor() const
Definition: dgGoogol.cpp:234
dgHugeVector::dgHugeVector
dgHugeVector(const dgTemplateVector< dgGoogol > &a)
Definition: dgGoogol.h:110
DG_GOOGOL_SIZE
#define DG_GOOGOL_SIZE
Definition: dgGoogol.h:34
dgStdafx.h
dgGoogol::operator>=
bool operator>=(const dgGoogol &A) const
Definition: dgGoogol.cpp:543
dgGoogol::m_one
static dgGoogol m_one
Definition: dgGoogol.h:90
dgGoogol::Abs
dgGoogol Abs() const
Definition: dgGoogol.cpp:227
dgGoogol::operator<
bool operator<(const dgGoogol &A) const
Definition: dgGoogol.cpp:549
dgGoogol
Definition: dgGoogol.h:36
dgGoogol::operator!=
bool operator!=(const dgGoogol &A) const
Definition: dgGoogol.cpp:567
dgGoogol::operator/
dgGoogol operator/(const dgGoogol &A) const
Definition: dgGoogol.cpp:209
dgGoogol::InvSqrt
dgGoogol InvSqrt() const
Definition: dgGoogol.cpp:262
dgGoogol::dgGoogol
dgGoogol(void)
Definition: dgGoogol.cpp:34
dgGoogol::operator>
bool operator>(const dgGoogol &A) const
Definition: dgGoogol.cpp:537
dgGoogol::Trace
void Trace() const
Definition: dgGoogol.cpp:577
dgGoogol::m_zero
static dgGoogol m_zero
Definition: dgGoogol.h:89
dgGoogol::m_two
static dgGoogol m_two
Definition: dgGoogol.h:91
dgGoogol::operator==
bool operator==(const dgGoogol &A) const
Definition: dgGoogol.cpp:561
dgGoogol::operator+
dgGoogol operator+(const dgGoogol &A) const
Definition: dgGoogol.cpp:74
dgGoogol::operator+=
dgGoogol operator+=(const dgGoogol &A)
Definition: dgGoogol.cpp:524
dgGoogol::operator-=
dgGoogol operator-=(const dgGoogol &A)
Definition: dgGoogol.cpp:530
dgBigVector
Definition: dgVector.h:207
dgHugeVector::dgHugeVector
dgHugeVector()
Definition: dgGoogol.h:100
dgArray.h