Skip to content

Commit 13ade98

Browse files
committed
Merge branch 'develop'
2 parents 065b065 + 1082123 commit 13ade98

File tree

8 files changed

+50
-38
lines changed

8 files changed

+50
-38
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build/
22
cmake-build-debug/
3-
.idea/workspace.xml
3+
.idea/workspace.xml
4+
.vscode/

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [v8.0.2] - 2019-05-22
10+
11+
### Added
12+
- `.vscode/` directory added to `.gitignore`.
13+
14+
### Fixed
15+
- Fixed bug where the `FpF` class was calculating incorrect results when peforming certain arithmetic (and when constructing), due to hard coded use of `int32_t`, where instead it should be using `BaseClass` (thanks [TheZoq2](https://github.com/TheZoq2) for finding this and sending in a MR). Added unit tests to prevent regresison.
16+
- Fixed URL to git repo in build section of README.
17+
- Updated dependencies in README.
18+
919
## [v8.0.1] - 2018-06-02
1020

1121
### Fixed

README.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ The cmake method will build the fixed point library and automatically runs all u
161161

162162
.. code:: bash
163163
164-
~$ git clone https://github.com/mbedded-ninja/MFixedPoint.git
164+
~$ git clone https://github.com/gbmhunter/MFixedPoint.git
165165
~$ cd MFixedPoint
166166
~/MFixedPoint$ mkdir build
167167
~/MFixedPoint$ cd build
@@ -253,6 +253,9 @@ The following table lists all of MFixedPoint's dependencies.
253253
====================== ==================== ======================================================================
254254
Dependency Delivery Usage
255255
====================== ==================== ======================================================================
256-
<cstdint> C standard library For platform agnostic fixed-width integers.
256+
<cstdint.h> C std lib. For platform agnostic fixed-width integers.
257+
<ostream> C++ std lib.
258+
<string> C++ std lib.
259+
<type_traits> C++ std lib.
257260
MUnitTest External module Framework for unit tests.
258261
====================== ==================== ======================================================================

include/MFixedPoint/FpF.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace MFixedPoint {
4242
/// prevent intermediary overflow problems.
4343
/// \note Slower than FpF::FixMulF()
4444
template<class BaseType, class OverflowType, uint8_t numFracBits>
45-
inline BaseType FpFMultiply(int32_t a, int32_t b) {
45+
inline BaseType FpFMultiply(BaseType a, BaseType b) {
4646
return (BaseType) (((OverflowType) a * b) >> numFracBits);
4747
}
4848

@@ -204,13 +204,13 @@ class FpF {
204204
}
205205

206206
FpF(int8_t i) :
207-
rawVal_((int32_t) i << numFracBits) {}
207+
rawVal_((BaseType) i << numFracBits) {}
208208

209209
FpF(int16_t i) :
210-
rawVal_((int32_t) i << numFracBits) {}
210+
rawVal_((BaseType) i << numFracBits) {}
211211

212212
FpF(int32_t i) :
213-
rawVal_(i << numFracBits) {}
213+
rawVal_((BaseType)i << numFracBits) {}
214214

215215
/// \brief Constructor that accepts a float.
216216
FpF(float f) :

test/FpF/FpFConversions.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! \author Geoffrey Hunter <[email protected]> (www.mbedded.ninja)
44
//! \edited n/a
55
//! \created 2013-07-22
6-
//! \last-modified 2018-01-10
6+
//! \last-modified 2019-05-22
77
//! \brief Performs unit tests on the fixed point FpF class.
88
//! \details
99
//! See README.rst in root dir for more info.
@@ -18,12 +18,6 @@ using namespace mn::MFixedPoint;
1818

1919
MTEST_GROUP(FpFConversions) {
2020

21-
// MTEST(README) {
22-
// FpS32 fp1(2.22, 8);
23-
// printf("ToInt<int32_t>() = %i\n", fp1.ToInt<int32_t>()); // Prints "ToInt<int32_t>() = 2"
24-
// printf("ToDouble() = %.2f\n", fp1.ToDouble()); // Prints "ToDouble() = 2.22"
25-
// }
26-
2721
// Check double->fixed conversion first as the
2822
// rest of the tests depend on it
2923
MTEST(PositiveDoubleToFixedConversionTest) {
@@ -80,4 +74,9 @@ MTEST_GROUP(FpFConversions) {
8074
FpF32<15> fp1(-34.982);
8175
CHECK_CLOSE((double)fp1, -34.982, 0.01);
8276
}
77+
78+
MTEST(ConstructFromIntTest) {
79+
FpF<int64_t, int64_t, 25> fp1 = 75;
80+
CHECK_CLOSE(fp1.ToInt<int64_t>(), 75, 0.1);
81+
}
8382
}

test/FpF/FpFWithFpFArithmeticTests.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! \author Geoffrey Hunter <[email protected]> (www.mbedded.ninja)
44
//! \edited n/a
55
//! \created 2013-07-22
6-
//! \last-modified 2018-02-11
6+
//! \last-modified 2019-05-22
77
//! \brief Performs unit tests on the fixed point FpF class.
88
//! \details
99
//! See README.rst in root dir for more info.
@@ -18,16 +18,6 @@ using namespace mn::MFixedPoint;
1818

1919
MTEST_GROUP(FpFArithmeticTests) {
2020

21-
// MTEST(ArithmeticOnReadme) {
22-
// FpS32 fp1(5.0, 8);
23-
// FpS32 fp2(1.5, 8);
24-
25-
// printf("add = %.2f\n", (fp1 + fp2).ToDouble());
26-
// printf("sub = %.2f\n", (fp1 - fp2).ToDouble());
27-
// printf("mult = %.2f\n", (fp1 * fp2).ToDouble());
28-
// printf("div = %.2f\n", (fp1 / fp2).ToDouble());
29-
// }
30-
3121
MTEST(AdditionSameNumFracBits) {
3222
FpF32<8> fp1(1.11);
3323
FpF32<8> fp2(2.22);
@@ -77,6 +67,13 @@ MTEST_GROUP(FpFArithmeticTests) {
7767
CHECK_CLOSE(fp3.ToDouble(), 1.92, 0.1);
7868
}
7969

70+
MTEST(OverflowMultiplicationTest) {
71+
FpF<int64_t, int64_t, 20> fp1(-4000.0);
72+
FpF<int64_t, int64_t, 20> fp2(-0.01);
73+
auto fp3 = fp1 * fp2;
74+
CHECK_CLOSE(fp3.ToDouble(), 40.0, 0.1);
75+
}
76+
8077
MTEST(PositiveDivisionTest) {
8178
FpF32<12> fp1(3.2);
8279
FpF32<12> fp2(0.6);

test/FpS/FpSArithmeticTests.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! \author Geoffrey Hunter <[email protected]> (www.mbedded.ninja)
44
//! \edited n/a
55
//! \created 2013-07-22
6-
//! \last-modified 2018-01-08
6+
//! \last-modified 2019-05-22
77
//! \brief Performs unit tests on the fixed point FpS class.
88
//! \details
99
//! See README.rst in root dir for more info.
@@ -18,16 +18,6 @@ using namespace mn::MFixedPoint;
1818

1919
MTEST_GROUP(FpSArithmeticTests) {
2020

21-
// MTEST(ArithmeticOnReadme) {
22-
// FpS32 fp1(5.0, 8);
23-
// FpS32 fp2(1.5, 8);
24-
25-
// printf("add = %.2f\n", (fp1 + fp2).ToDouble());
26-
// printf("sub = %.2f\n", (fp1 - fp2).ToDouble());
27-
// printf("mult = %.2f\n", (fp1 * fp2).ToDouble());
28-
// printf("div = %.2f\n", (fp1 / fp2).ToDouble());
29-
// }
30-
3121
MTEST(AdditionSameNumFracBits) {
3222
FpS32 fp1(1.11, 8);
3323
FpS32 fp2(2.22, 8);
@@ -101,6 +91,13 @@ MTEST_GROUP(FpSArithmeticTests) {
10191
CHECK_CLOSE(1.92, fp3.ToDouble(), 0.1);
10292
}
10393

94+
MTEST(OverflowMultiplicationTest) {
95+
FpS<int64_t, int64_t> fp1(-4000.0, 20);
96+
FpS<int64_t, int64_t> fp2(-0.01, 20);
97+
auto fp3 = fp1 * fp2;
98+
CHECK_CLOSE(fp3.ToDouble(), 40.0, 0.1);
99+
}
100+
104101
MTEST(PositiveDivisionTest) {
105102
FpS32 fp1(3.2, 12);
106103
FpS32 fp2(0.6, 12);

test/FpS/FpSConstructors.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! \author Geoffrey Hunter <[email protected]> (www.mbedded.ninja)
44
//! \edited n/a
55
//! \created 2018-01-08
6-
//! \last-modified 2017-01-08
6+
//! \last-modified 2019-05-22
77
//! \brief Performs unit tests on the fixed point FpS class.
88
//! \details
99
//! See README.rst in root dir for more info.
@@ -18,11 +18,16 @@ using namespace mn::MFixedPoint;
1818

1919
MTEST_GROUP(FpSTests) {
2020

21-
MTEST(CreateFromInteger) {
21+
MTEST(CreateFromIntFpS32) {
2222
FpS32 fp1(34, 0);
2323
CHECK_EQUAL(fp1.GetRawVal(), 34 << 0);
2424
}
2525

26+
MTEST(CreateFromIntFpS64) {
27+
FpS<int64_t, int64_t> fp1(75, 20);
28+
CHECK_CLOSE(fp1.ToInt<int64_t>(), 75, 0.1);
29+
}
30+
2631
MTEST(CreateFromFloat) {
2732
FpS32 fp1(34.2f, 8);
2833
CHECK_EQUAL(fp1.GetRawVal(), (int32_t)(34.2f * (1 << 8)));

0 commit comments

Comments
 (0)