Skip to content

Commit 74e8cbe

Browse files
author
Geoffrey Hunter
committed
Merge branch 'develop'
2 parents 0656856 + a9c045e commit 74e8cbe

File tree

14 files changed

+482
-155
lines changed

14 files changed

+482
-155
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88

9+
## [v8.0.0-beta.2] - 2018-01-11
10+
11+
### Added
12+
- Added compile time check to `FpF` class to make sure template parameters are the same before doing multiplication.
13+
- Added README code to a new example folder (to make sure it compiles correctly).
14+
- Added conversion methods, casting capabilities and associated unit tests for the `FpF` class.
15+
16+
### Fixed
17+
- Removed reference to non-existant MFixedPoint library when linking the benchmark and unit test code.
18+
- Fixed failing `sudo make install` command.
19+
- Fixed failing FpF multiplication.
20+
- Fixed bug where `FpF` constructor accepting a double was first converting value to a float.
21+
- Example in README now compiles correctly.
22+
- Fixed bug where bit-shifting was overflowing in fixed-point constructors from doubles because '1' was not being cast to BaseType first.
23+
924
## [v8.0.0-beta.1] - 2018-01-09
1025

1126
### Added
@@ -34,3 +49,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3449
### Changed
3550
- Changed the `Fp` namespace to `MFixedPoint` (to reflect actual project name), closes #86.
3651
- Modified header guard macros to include the text `MN_MFIXEDPOINT_...` (to include organization/project name).
52+
53+
[Unreleased]: https://github.com/mbedded-ninja/CppTemplate/compare/v8.0.0-beta.2...HEAD
54+
[v8.0.0-beta.2]: https://github.com/mbedded-ninja/CppTemplate/compare/v8.0.0-beta.1...v8.0.0-beta.2
55+
[v8.0.0-beta.1]: https://github.com/mbedded-ninja/CppTemplate/compare/v7.0.1...v8.0.0-beta.1
56+
[v7.0.1]: https://github.com/mbedded-ninja/CppTemplate/compare/v7.0.0...v7.0.1

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,10 @@ if(BUILD_TESTS)
6464
endif()
6565
add_subdirectory(benchmark)
6666

67+
add_subdirectory(example)
68+
69+
# On Linux, "sudo make install" will typically copy the
70+
# folder into /usr/local/include
71+
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/MFixedPoint DESTINATION include)
6772

6873

README.rst

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ This library has been tested on:
127127
- Linux (Ubuntu)
128128
- A CodeAnywhere "DevBox"
129129

130-
Configuration
131-
=============
132-
133-
Configuration settings are in :code:`include/Config.hpp`. This file allows you to turn on/off debug message printing (which itself is port-specific, and defined in :code:`include/Port.hpp/cpp`).
134-
135130
Compiling
136131
=========
137132

@@ -149,55 +144,74 @@ The cmake method will build the fixed point library and automatically runs all u
149144
~/MFixedPoint/build$ cmake ..
150145
~/MFixedPoint/build$ make
151146
152-
You can then the tests by calling:
147+
You can run the tests manually by calling:
153148

154149
.. code:: bash
155150
156151
~/MFixedPoint/build$ ./test/MFixedPointTests
157152
158-
Usage
159-
=====
153+
Examples
154+
========
160155

161156
See the unit tests in :code:`test/` for more usage examples!
162157

163158
.. code:: cpp
164159
165-
// Include the API header which provides access to all of the fixed-point
166-
// data types
167-
#include "MFixedPoint/api/MFixedPointApi.hpp"
160+
// System includes
161+
#include <iostream>
162+
163+
// 3rd party includes
164+
#include "MFixedPoint/FpS.hpp"
165+
#include "MFixedPoint/FpF.hpp"
166+
167+
using namespace mn::MFixedPoint;
168+
169+
int main() {
170+
171+
//================================================================================================//
172+
//================================= Slow Fixed-Point Numbers (FpS) ===============================//
173+
//================================================================================================//
174+
175+
// Creating a 32-bit "slow" fixed-point number (notice the slightly different syntax to FpF)
176+
FpS32 fpSNum1(12.23, 12);
177+
std::cout << "fpSNum1 = " << (double)fpSNum1 << std::endl;
178+
179+
FpS32 fpSNum2(5.12, 16);
180+
std::cout << "fpSNum2 = " << (double)fpSNum2 << std::endl;
181+
182+
std::cout << "fpSNum1 + fpSNum2 = " << (double)(fpSNum1 + fpSNum2) << std::endl;
183+
std::cout << "fpSNum1 - fpSNum2 = " << (double)(fpSNum1 - fpSNum2) << std::endl;
184+
std::cout << "fpSNum1 * fpSNum2 = " << (double)(fpSNum1 * fpSNum2) << std::endl;
185+
std::cout << "fpSNum1 / fpSNum2 = " << (double)(fpSNum1 / fpSNum2) << std::endl;
186+
std::cout << "fpSNum1 % fpSNum2 = " << (double)(fpSNum1 % fpSNum2) << std::endl;
187+
188+
//================================================================================================//
189+
//================================= Fast Fixed-Point Numbers (FpF) ===============================//
190+
//================================================================================================//
168191
169-
int main()
170-
{
171192
// Create two 32-bit fast fixed-point numbers with 24 decimal bits and 8 fractional bits.
172193
// This constructor converts from doubles
173-
Fp32f<8> aFpNum1 = Fp32f<8>(3.2);
174-
Fp32f<8> aFpNum2 = Fp32f<8>(0.6);
194+
FpF32<8> fpNum1(3.2);
195+
FpF32<8> fpNum2(0.6);
175196
176197
// Performing a quick fixed-point addition
177-
Fp32f<8> aFpNum3 = aFpNum1 + aFpNum2;
198+
auto fpNum3 = fpNum1 + fpNum2;
178199
179200
// Performing a quick fixed-point multiplication
180-
Fp32f<8> aFpNm4 = aFpNum1 * aFpNum2;
201+
auto fpNum4 = fpNum1 * fpNum2;
181202
182203
// Printing the result as a double, using the Fix32ToDouble() method
183204
// Note that if you use slow fixed-point data type instead, you can
184205
// directly cast one to a double
185-
std::cout << "My fast 32-bit fixed-point number = " << Fix32ToDouble(aFpNum4);
206+
std::cout << "My fast 32-bit fixed-point number = " << (double)fpNum4;
186207
187208
// Converting between different precisions. Requires access to raw value just like
188209
// when doing fixed-point to double conversion.
189-
Fp32f<20> aHigherPrecisionNum = Fp32f<20>(7.5);
190-
Fp32f<12> aLowerPrecisionNum.rawVal = aHigherPrecisionNum.rawVal >> (20 - 12);
210+
FpF32<20> aHigherPrecisionNum(7.5);
211+
// FpF32<12> aLowerPrecisionNum.rawVal = aHigherPrecisionNum.rawVal >> (20 - 12);
191212
192213
// You can use 64-bit fixed point numbers in exactly the same way!
193-
Fp64f<48> aFp64Num = Fp64f<48>(4.58676);
194-
195-
// Creating a 32-bit slow fixed-point number (notice the slightly different syntax)
196-
Fp32s mySlowFp32Num = Fp32s(12.23, 12);
197-
198-
// You can cast slow 32-bit fixed-point numbers back to doubles
199-
// (you can't do this with the fast fixed-point data types)
200-
std::cout << "My slow 32-bit fixed-point number = " << (double)mySlowFp32Num;
214+
FpF64<48> aFp64Num(4.58676);
201215
202216
return 0;
203217
}

benchmark/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ file(GLOB_RECURSE MFixedPoint_Benchmark_SRC
55
add_executable (MFixedPoint_Benchmark ${MFixedPoint_Benchmark_SRC})
66
target_compile_options(MFixedPoint_Benchmark PUBLIC -Wall)
77

8-
target_link_libraries(MFixedPoint_Benchmark LINK_PUBLIC MFixedPoint)
8+
# target_link_libraries(MFixedPoint_Benchmark LINK_PUBLIC MFixedPoint)
99

1010
add_custom_target(
1111
fake_target_to_run_benchmark ALL

example/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
add_executable(ReadmeExample ReadmeExample.cpp)
4+

example/ReadmeExample.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
///
2+
/// \file ReadmeExample.cpp
3+
/// \author Geoffrey Hunter <[email protected]> (www.mbedded.ninja)
4+
/// \edited n/a
5+
/// \created 2018-01-10
6+
/// \last-modified 2017-01-11
7+
/// \brief Contains the example code that is shown in the README.
8+
/// \details
9+
/// See README.rst in root dir for more info.
10+
11+
// System includes
12+
#include <iostream>
13+
14+
// 3rd party includes
15+
#include "MFixedPoint/FpS.hpp"
16+
#include "MFixedPoint/FpF.hpp"
17+
18+
using namespace mn::MFixedPoint;
19+
20+
int main() {
21+
22+
//================================================================================================//
23+
//================================= Slow Fixed-Point Numbers (FpS) ===============================//
24+
//================================================================================================//
25+
26+
// Creating a 32-bit "slow" fixed-point number (notice the slightly different syntax to FpF)
27+
FpS32 fpSNum1(12.23, 12);
28+
std::cout << "fpSNum1 = " << (double)fpSNum1 << std::endl;
29+
30+
FpS32 fpSNum2(5.12, 16);
31+
std::cout << "fpSNum2 = " << (double)fpSNum2 << std::endl;
32+
33+
std::cout << "fpSNum1 + fpSNum2 = " << (double)(fpSNum1 + fpSNum2) << std::endl;
34+
std::cout << "fpSNum1 - fpSNum2 = " << (double)(fpSNum1 - fpSNum2) << std::endl;
35+
std::cout << "fpSNum1 * fpSNum2 = " << (double)(fpSNum1 * fpSNum2) << std::endl;
36+
std::cout << "fpSNum1 / fpSNum2 = " << (double)(fpSNum1 / fpSNum2) << std::endl;
37+
std::cout << "fpSNum1 % fpSNum2 = " << (double)(fpSNum1 % fpSNum2) << std::endl;
38+
39+
//================================================================================================//
40+
//================================= Fast Fixed-Point Numbers (FpF) ===============================//
41+
//================================================================================================//
42+
43+
// Create two 32-bit fast fixed-point numbers with 24 decimal bits and 8 fractional bits.
44+
// This constructor converts from doubles
45+
FpF32<8> fpNum1(3.2);
46+
FpF32<8> fpNum2(0.6);
47+
48+
// Performing a quick fixed-point addition
49+
auto fpNum3 = fpNum1 + fpNum2;
50+
51+
// Performing a quick fixed-point multiplication
52+
auto fpNum4 = fpNum1 * fpNum2;
53+
54+
// Printing the result as a double, using the Fix32ToDouble() method
55+
// Note that if you use slow fixed-point data type instead, you can
56+
// directly cast one to a double
57+
std::cout << "My fast 32-bit fixed-point number = " << (double)fpNum4;
58+
59+
// Converting between different precisions. Requires access to raw value just like
60+
// when doing fixed-point to double conversion.
61+
FpF32<20> aHigherPrecisionNum(7.5);
62+
// FpF32<12> aLowerPrecisionNum.rawVal = aHigherPrecisionNum.rawVal >> (20 - 12);
63+
64+
// You can use 64-bit fixed point numbers in exactly the same way!
65+
FpF64<48> aFp64Num(4.58676);
66+
67+
return 0;
68+
}

0 commit comments

Comments
 (0)