Skip to content

Commit 3c75084

Browse files
committed
Tidy up for initial release
- spruced up docs - added Fixed::MIN() and Fixed::MAX() constant-like functions for min and max range of type, along with tests for them. - added todo-list in docs
1 parent 240b03f commit 3c75084

File tree

4 files changed

+52
-63
lines changed

4 files changed

+52
-63
lines changed

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ PROJECT_NUMBER = $(TAG_NAME)
4444
# for a project that appears at the top of each page and should give viewer a
4545
# quick idea about the purpose of the project. Keep the description short.
4646

47-
PROJECT_BRIEF = "Lazy-evaluated type-wrapper for numeric types in C++"
47+
PROJECT_BRIEF = "More convenient fixed-point arithmetic for the Sony PlayStation"
4848

4949
# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
5050
# in the documentation. The maximum height of the logo should not exceed 55

README.md

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,4 @@
1-
# CPP20-Cross-Platform-Template
2-
A template for a cross-platform C++20 project including modern CMake, unit-testing with Catch, cross-platform CI and release builds using using Github Actions.
1+
# SxPsxFp
2+
More convenient fixed-point arithmetic for the Sony PlayStation
33

4-
## What's included
5-
- CMake C++20 project skeleton, with strict warning flags enabled when using GCC or Clang.
6-
- Usage of modern CMake practices for setting project-wide compiler options, etc. in a target-focused way.
7-
- Properly exported CMake project that can be used by other CMake projects with minimal effort (no hand-written `FindMyProject.cmake` files)
8-
- Unit testing using [Catch2](https://github.com/catchorg/Catch2), with automatic test discovery integration with CTest.
9-
- Github Actions config files supporting building and running tests on Linux, macOS and Windows using the following compilers:
10-
- Linux: GCC-10, Clang-10
11-
- macOS: GCC-10, Clang-12
12-
- Windows: MSVC 2019
13-
- Building Releases on each platform when a Github Release is published, uploading these as build Artifacts.
14-
- Doxygen config file with tweaks from the default config settings to provide a few more graphs (usage, caller/callee relationships) than are enabled by default.
15-
16-
> **Note** There's also a Travis-CI build config for a cross-platform build of similar structure to the Github Actions builds, however this is no longer maintained as Travis-CI has been found to not support more recent versions of CMake on all platforms.
17-
18-
## Usage
19-
1. Click the <kbd>Use this template</kbd> button at the top of this page to create your own new copy of this template
20-
2. Fill in the project details on the next page as you desire
21-
3. Once you've got your new project produced from this template, make changes in the following files:
22-
- `CMakeLists.txt`, `project/CMakeLists.txt`, `project/src/CMakeLists.txt`, `tests/CMakeLists.txt`:
23-
- Replace all instances of `PROJECT`, `project` and `Project` with your project's name, capitalised or uncapitalised as appropriate
24-
- `Doxyfile`:
25-
- Change the `PROJECT_NAME` and `INPUT` settings to your project's name.
26-
- `project`:
27-
- Rename this directory to the name of your project.
28-
- **Choose a Software License for your code** if it is open-source and you want other people to be able to use it with ease!
29-
30-
This _project template_ is placed into the public domain, but you may want to use a different license for your own projects that you create from this template. Here is the public domain dedication text for this project:
31-
32-
```
33-
This is free and unencumbered software released into the public domain.
34-
35-
Anyone is free to copy, modify, publish, use, compile, sell, or
36-
distribute this software, either in source code form or as a compiled
37-
binary, for any purpose, commercial or non-commercial, and by any
38-
means.
39-
40-
In jurisdictions that recognize copyright laws, the author or authors
41-
of this software dedicate any and all copyright interest in the
42-
software to the public domain. We make this dedication for the benefit
43-
of the public at large and to the detriment of our heirs and
44-
successors. We intend this dedication to be an overt act of
45-
relinquishment in perpetuity of all present and future rights to this
46-
software under copyright law.
47-
48-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
49-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
50-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
51-
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
52-
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
53-
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
54-
OTHER DEALINGS IN THE SOFTWARE.
55-
56-
For more information, please refer to <http://unlicense.org/>
57-
```
58-
4. Enjoy!
59-
60-
> The above instructions are the bare minimum required to get your own project based on this template off of the ground. You'll almost certainly want to change more things in `Doxyfile` and definitely `README.md`, but that should be well within the capabilities of a developer and also beyond the scope of this guide.
4+
- [sxpsxfp](@ref com::saxbophone::sxpsxfp) API reference

sxpsxfp/include/sxpsxfp/Fixed.hpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include <sys/types.h>
2424
#endif
2525

26+
/**
27+
* @todo Consider shortening the namespace name to its last component
28+
* @todo Consider choosing a more intuitive name than @b sxpsxfp
29+
*/
2630
namespace com::saxbophone::sxpsxfp {
2731
class Fixed; // forward-declaration to allow declaration of user-defined literals
2832

@@ -60,6 +64,7 @@ namespace com::saxbophone::sxpsxfp {
6064
* point arithmetic and allows arithmetic operations to be done on these
6165
* instances directly, handling the additional arithmetic for emulating
6266
* fixed-point internally.
67+
* @todo Document constants
6368
*/
6469
class Fixed {
6570
public:
@@ -72,6 +77,15 @@ namespace com::saxbophone::sxpsxfp {
7277
static constexpr UnderlyingType DECIMAL_MIN = -(1 << Fixed::DECIMAL_BITS);
7378
static constexpr double FRACTIONAL_MAX = Fixed::DECIMAL_MAX + (1.0 - Fixed::FRACTIONAL_STEP);
7479
static constexpr double FRACTIONAL_MIN = Fixed::DECIMAL_MIN - (1.0 - Fixed::FRACTIONAL_STEP);
80+
81+
static constexpr Fixed MAX() {
82+
return Fixed((UnderlyingType)2147483647);
83+
}
84+
85+
static constexpr Fixed MIN() {
86+
return Fixed((UnderlyingType)-2147483648);
87+
}
88+
7589
/**
7690
* @brief Default constructor, creates a Fixed instance with value `0.0_fx`
7791
*/
@@ -93,6 +107,9 @@ namespace com::saxbophone::sxpsxfp {
93107
* @note Not recommended to use this outside of constexpr contexts
94108
* where avoidable on the PlayStation, as the console has no hardware
95109
* floating point support, so slow software floats will be used.
110+
* @todo Consider adding a single-precision `float` version of this
111+
* methodfor faster emulation when doing runtime conversions on the
112+
* PlayStation and `double` precision is not needed.
96113
*/
97114
constexpr Fixed(double value) {
98115
double scaled = value * Fixed::SCALE;
@@ -111,9 +128,9 @@ namespace com::saxbophone::sxpsxfp {
111128
* @warning Don't use this for converting raw fixed-point integers to Fixed.
112129
* Use Fixed::Fixed(UnderlyingType) for that.
113130
* @see Fixed::Fixed(UnderlyingType)
131+
* @todo Check for overflow? No exceptions on the PS1...
114132
*/
115133
static constexpr Fixed from_integer(int value) {
116-
// TODO: Check for overflow? No exceptions on the PS1...
117134
return Fixed(value << Fixed::FRACTION_BITS);
118135
}
119136
/**
@@ -202,32 +219,44 @@ namespace com::saxbophone::sxpsxfp {
202219
}
203220
/**
204221
* @brief Compound assignment multiplication operator
222+
* @todo Investigate performance impact of compiler-generated 64-bit
223+
* multiplication emulation on 32-bit MIPS. If poor performance,
224+
* consider utilising Lameguy64's suggested implementation using inline
225+
* assembly to take advantage of the R3000's 64-bit double-word multiply
226+
* feature.
205227
*/
206228
constexpr Fixed& operator *=(const Fixed& rhs) {
207-
// XXX: no int64_t on PS1, needs rewrite to run on that platform
229+
// XXX: no int64_t on PS1, software emulation kicks in automatically
208230
int64_t result = (int64_t)this->_raw_value * rhs._raw_value;
209231
// shift back down
210232
this->_raw_value = (UnderlyingType)(result / Fixed::SCALE);
211233
return *this;
212234
}
213235
/**
214236
* @brief Compound assignment integer multiplication operator
237+
* @todo Investigate overflow?
215238
*/
216239
constexpr Fixed& operator *=(const UnderlyingType& rhs) {
217240
this->_raw_value *= rhs;
218241
return *this;
219242
}
220243
/**
221244
* @brief Compound assignment division operator
245+
* @todo Investigate performance impact of compiler-generated 64-bit
246+
* multiplication emulation on 32-bit MIPS. If poor performance,
247+
* consider utilising Lameguy64's suggested implementation using inline
248+
* assembly to take advantage of the R3000's 64-bit double-word multiply
249+
* feature.
222250
*/
223251
constexpr Fixed& operator /=(const Fixed& rhs) {
224-
// XXX: no int64_t on PS1, needs rewrite to run on that platform
252+
// XXX: no int64_t on PS1, software emulation kicks in automatically
225253
int64_t scaled = (int64_t)this->_raw_value * Fixed::SCALE;
226254
this->_raw_value = (UnderlyingType)(scaled / rhs._raw_value);
227255
return *this;
228256
}
229257
/**
230258
* @brief Compound assignment integer division operator
259+
* @todo Investigate overflow?
231260
*/
232261
constexpr Fixed& operator /=(const UnderlyingType& rhs) {
233262
this->_raw_value /= rhs;

tests/static_checks.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ TEST_CASE("Fixed::FRACTIONAL_MIN == Fixed::DECIMAL_MIN - (1 - Fixed::FRACTIONAL_
5353
STATIC_REQUIRE(Fixed::FRACTIONAL_MIN == Fixed::DECIMAL_MIN - (1.0 - Fixed::FRACTIONAL_STEP));
5454
}
5555

56+
TEST_CASE("Fixed::MAX() == Max 32-bit signed integer") {
57+
STATIC_REQUIRE(Fixed::MAX() == Fixed(INT_MAX));
58+
}
59+
60+
TEST_CASE("Fixed::MIN() == Min 32-bit signed integer") {
61+
STATIC_REQUIRE(Fixed::MIN() == Fixed(INT_MIN));
62+
}
63+
64+
TEST_CASE("typeof(Fixed::MAX()) == Fixed") {
65+
STATIC_REQUIRE(std::is_same_v<decltype(Fixed::MAX()), Fixed>);
66+
}
67+
68+
TEST_CASE("typeof(Fixed::MIN()) == Fixed") {
69+
STATIC_REQUIRE(std::is_same_v<decltype(Fixed::MIN()), Fixed>);
70+
}
71+
5672
TEST_CASE("typeof(Fixed + Fixed) == Fixed") {
5773
Fixed x = {}, y = {};
5874
STATIC_REQUIRE(std::is_same_v<decltype(x + y), Fixed>);

0 commit comments

Comments
 (0)