MathLib
Loading...
Searching...
No Matches
TestDualNumber.cpp
Go to the documentation of this file.
1#include <Math/math/Dual.hpp>
3#include <cassert>
4#include <iostream>
5#include <cstdlib>
6
26{
27
28using namespace Math;
29
33{
34 std::cout << __func__ << std::endl;
35
36 Dualf identity = Dualf::identity();
37
38 CHECK_IF_EQUAL(identity.real, 1.0f);
39 CHECK_IF_EQUAL(identity.dual, 0.0f);
40}
41
45{
46 std::cout << __func__ << std::endl;
47
48 Dualf zero = Dualf::zero();
49
50 CHECK_IF_EQUAL(zero.real, 0.0f);
51 CHECK_IF_EQUAL(zero.dual, 0.0f);
52}
53
57{
58 std::cout << __func__ << std::endl;
59
60 CHECK_IF_EQUAL( Dualf::make_pure(3.0f).real, 0.0f );
61}
62
66{
67 std::cout << __func__ << std::endl;
68
69 CHECK_IF_EQUAL( Dualf::make_pure(3.3f).dual, 3.3f );
70}
71
76{
77 std::cout << __func__ << std::endl;
78
79 Dualf d1{ 1.0f, 3.0f };
80 Dualf d2{ 9.0f, 11.0f };
81
82 CHECK_IF_EQUAL( dot( d1, d2 ), 42.0f );
83}
84
89{
90 std::cout << __func__ << std::endl;
91
92 Dualf original_number{ 3.456f, 86.332f };
93 Dualf root = dualscalar_sqrt(original_number);
94 Dualf root_squared = root * root;
95
96 CHECK_IF_EQUAL( original_number, root_squared );
97}
98
100{
101 Dual d( 12.0 );
102
103 assert( d == 12.0 );
104 assert( 12.0 == d );
105 assert( d == Dual( 12.0 ) );
106}
107
109{
110 Dual d( 16.0 );
111 Dual r = d * 2.0;
112
113 assert( r == 32.0 );
114 assert( r == Dual( 32.0 ) );
115 assert( 32.0 == r );
116 assert( Dual( 32.0 ) == r );
117}
118
120{
123}
124
128void Run()
129{
130 std::cout << "Running Dual Number Tests..." << std::endl;
131
138
139 std::cout << "PASSED!" << std::endl;
140}
141}
143
144int main(void)
145{
147 return EXIT_SUCCESS;
148}
int main(void)
void CHECK_IF_EQUAL(float input, float near_to, float tolerance=0.0002f)
Definition Checks.hpp:127
void DualScalarSquareRootTimesItselfIsTheOriginalNumber()
void DotProductMultiplesCorrespondingElementsAndThenSumsTheResultingValues()
void IdentityDualIsAsExpected()
void MakePureDualSetsDualComponentToGivenValue()
void MakePureDualSetsRealComponentToZero()
Definition Angle.hpp:16