From af87f2de2a1ffeaaa53a0689930ba6a796f8966b Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Tue, 21 Sep 2021 12:36:54 +0100 Subject: [PATCH 01/18] Improved head documentation in public header file --- unmoving/include/unmoving/Fixed.hpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/unmoving/include/unmoving/Fixed.hpp b/unmoving/include/unmoving/Fixed.hpp index 74d0a96..b1e5c9d 100644 --- a/unmoving/include/unmoving/Fixed.hpp +++ b/unmoving/include/unmoving/Fixed.hpp @@ -1,6 +1,16 @@ /** * @file - * This file forms part of unmoving + * @brief This file forms part of Unmoving + * @details Unmoving is a C++ header-only library providing more convenient + * fixed-point arithmetic for the Sony PlayStation ("PS1"), in the form of a + * C++ class that wraps the native integer type used by the console standard + * library for performing fixed-point calculations. This class is intended to + * remove much of the more tedious aspects of the boilerplate code required to + * handle numbers in this way. The author hopes that it is useful. + * @warning Performance testing has not been done either in emulators or real + * PlayStation hardware. Although effort has been made to make this code + * efficient, at this stage this cannot be guaranteed, particularly with + * multiplication or division between two Fixed instances. * * @author Joshua Saxby * @date September 2021 @@ -8,8 +18,9 @@ * @copyright Copyright Joshua Saxby 2021 * * @copyright - * This is closed-source software and may not be used in any way without the - * express written permission of the copyright holder. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef COM_SAXBOPHONE_UNMOVING_UNMOVING_HPP @@ -25,10 +36,6 @@ #include // snprintf #include // abs -/** - * @todo Consider shortening the namespace name to its last component - * @todo Consider choosing a more intuitive name than @b unmoving - */ namespace com::saxbophone::unmoving { class Fixed; // forward-declaration to allow declaration of user-defined literals From dfae7e34d516e0bca41fc49c132411ee0f770c2c Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Tue, 21 Sep 2021 12:40:51 +0100 Subject: [PATCH 02/18] Add file license headers to all other source files MPL-2.0 FTW! --- tests/addition.cpp | 11 +++++++++++ tests/casting.cpp | 13 ++++++++++++- tests/comparisons.cpp | 13 ++++++++++++- tests/config.hpp | 13 ++++++++++++- tests/constructors.cpp | 13 ++++++++++++- tests/conversion_to_string.cpp | 13 ++++++++++++- tests/conversion_to_string_null.cpp | 13 ++++++++++++- tests/division.cpp | 13 ++++++++++++- tests/equivalences.cpp | 13 ++++++++++++- tests/main.cpp | 12 ++++++++++++ tests/multiplication.cpp | 13 ++++++++++++- tests/static_checks.cpp | 13 ++++++++++++- tests/subtraction.cpp | 13 ++++++++++++- tests/unary_operations.cpp | 13 ++++++++++++- tests/user_defined_literals.cpp | 13 ++++++++++++- 15 files changed, 179 insertions(+), 13 deletions(-) diff --git a/tests/addition.cpp b/tests/addition.cpp index c276292..5312d77 100644 --- a/tests/addition.cpp +++ b/tests/addition.cpp @@ -1,3 +1,14 @@ +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ #include #include diff --git a/tests/casting.cpp b/tests/casting.cpp index c2396df..3c02a29 100644 --- a/tests/casting.cpp +++ b/tests/casting.cpp @@ -1,4 +1,15 @@ -#include +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #include #include diff --git a/tests/comparisons.cpp b/tests/comparisons.cpp index 83eca59..2d0cd04 100644 --- a/tests/comparisons.cpp +++ b/tests/comparisons.cpp @@ -1,4 +1,15 @@ -#include +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #include #include diff --git a/tests/config.hpp b/tests/config.hpp index 05af380..c98ef65 100644 --- a/tests/config.hpp +++ b/tests/config.hpp @@ -1,4 +1,15 @@ -#ifndef COM_SAXBOPHONE_UNMOVING_TESTS_CONFIG_HPP +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #ifndef COM_SAXBOPHONE_UNMOVING_TESTS_CONFIG_HPP #define COM_SAXBOPHONE_UNMOVING_TESTS_CONFIG_HPP #include diff --git a/tests/constructors.cpp b/tests/constructors.cpp index b8f8e98..4223861 100644 --- a/tests/constructors.cpp +++ b/tests/constructors.cpp @@ -1,4 +1,15 @@ -#include +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #include #include diff --git a/tests/conversion_to_string.cpp b/tests/conversion_to_string.cpp index 919248a..16ed3b9 100644 --- a/tests/conversion_to_string.cpp +++ b/tests/conversion_to_string.cpp @@ -1,4 +1,15 @@ -#include +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #include #include diff --git a/tests/conversion_to_string_null.cpp b/tests/conversion_to_string_null.cpp index edead31..2dd8040 100644 --- a/tests/conversion_to_string_null.cpp +++ b/tests/conversion_to_string_null.cpp @@ -1,4 +1,15 @@ -#include +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #include #include diff --git a/tests/division.cpp b/tests/division.cpp index 010e046..ee24fe5 100644 --- a/tests/division.cpp +++ b/tests/division.cpp @@ -1,4 +1,15 @@ -#include +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #include #include diff --git a/tests/equivalences.cpp b/tests/equivalences.cpp index 800f686..f4800e2 100644 --- a/tests/equivalences.cpp +++ b/tests/equivalences.cpp @@ -1,4 +1,15 @@ -#include +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #include #include diff --git a/tests/main.cpp b/tests/main.cpp index 3bb85f8..91d01be 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,4 +1,16 @@ /* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + + /* * This is the Unit-testing entry point as recommended by Catch, the framework * being used for unit-testing: * https://github.com/catchorg/Catch2/blob/master/docs/slow-compiles.md#practical-example diff --git a/tests/multiplication.cpp b/tests/multiplication.cpp index f0b6c2a..a4235b3 100644 --- a/tests/multiplication.cpp +++ b/tests/multiplication.cpp @@ -1,4 +1,15 @@ -#include +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #include #include diff --git a/tests/static_checks.cpp b/tests/static_checks.cpp index 2e883fe..520435a 100644 --- a/tests/static_checks.cpp +++ b/tests/static_checks.cpp @@ -1,4 +1,15 @@ -#include +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #include #include // defer static checks to runtime diff --git a/tests/subtraction.cpp b/tests/subtraction.cpp index e87d12f..04165ec 100644 --- a/tests/subtraction.cpp +++ b/tests/subtraction.cpp @@ -1,4 +1,15 @@ -#include +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #include #include #include diff --git a/tests/unary_operations.cpp b/tests/unary_operations.cpp index b905247..8827e26 100644 --- a/tests/unary_operations.cpp +++ b/tests/unary_operations.cpp @@ -1,4 +1,15 @@ -#include +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #include #include diff --git a/tests/user_defined_literals.cpp b/tests/user_defined_literals.cpp index 1d71374..e18a7d2 100644 --- a/tests/user_defined_literals.cpp +++ b/tests/user_defined_literals.cpp @@ -1,4 +1,15 @@ -#include +/* + * This source file forms part of Unmoving + * Unmoving is a C++ header-only library providing more convenient fixed-point + * arithmetic for the Sony PlayStation ("PS1"). + * + * Copyright Joshua Saxby 2021 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + #include #include From cd7979a2548deda9fd9070081ba20d253006f419 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Tue, 21 Sep 2021 12:42:19 +0100 Subject: [PATCH 03/18] Add MPL-2.0 main license file --- LICENSE | 373 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 373 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a612ad9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. From 6ae18060ad14b1611028e8675e61d0bc2da31dd1 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 05:25:09 +0100 Subject: [PATCH 04/18] Renamed Fixed class to PSXFixed for exactness Also, this will free up the name to allow for a generic Fixed type to be added in the future withoutn needing to break any existing code that uses Fixed. --- tests/addition.cpp | 28 ++-- tests/casting.cpp | 16 +- tests/comparisons.cpp | 120 +++++++------- tests/constructors.cpp | 30 ++-- tests/conversion_to_string.cpp | 18 +- tests/conversion_to_string_null.cpp | 6 +- tests/division.cpp | 32 ++-- tests/equivalences.cpp | 16 +- tests/multiplication.cpp | 40 ++--- tests/static_checks.cpp | 152 ++++++++--------- tests/subtraction.cpp | 28 ++-- tests/unary_operations.cpp | 50 +++--- tests/user_defined_literals.cpp | 22 +-- .../unmoving/{Fixed.hpp => PSXFixed.hpp} | 156 +++++++++--------- 14 files changed, 357 insertions(+), 357 deletions(-) rename unmoving/include/unmoving/{Fixed.hpp => PSXFixed.hpp} (69%) diff --git a/tests/addition.cpp b/tests/addition.cpp index 5312d77..e13b972 100644 --- a/tests/addition.cpp +++ b/tests/addition.cpp @@ -16,23 +16,23 @@ #include -#include +#include #include "config.hpp" using namespace com::saxbophone::unmoving; -using Underlying = Fixed::UnderlyingType; +using Underlying = PSXFixed::UnderlyingType; // calculated propagated accuracy error after an addition -constexpr double ACCURACY = Fixed::ACCURACY * 2.0; +constexpr double ACCURACY = PSXFixed::ACCURACY * 2.0; TEST_CASE("Addition") { double i = GENERATE( take( tests_config::ITERATIONS, random( - Fixed::FRACTIONAL_MIN, - Fixed::FRACTIONAL_MAX + PSXFixed::FRACTIONAL_MIN, + PSXFixed::FRACTIONAL_MAX ) ) ); @@ -43,28 +43,28 @@ TEST_CASE("Addition") { filter( [=](double u) { auto sum = i + u; - return Fixed::FRACTIONAL_MIN <= sum and - sum <= Fixed::FRACTIONAL_MAX; + return PSXFixed::FRACTIONAL_MIN <= sum and + sum <= PSXFixed::FRACTIONAL_MAX; }, random( - Fixed::FRACTIONAL_MIN, - Fixed::FRACTIONAL_MAX + PSXFixed::FRACTIONAL_MIN, + PSXFixed::FRACTIONAL_MAX ) ) ) ); - Fixed foo(i); - Fixed bar(j); + PSXFixed foo(i); + PSXFixed bar(j); // use calculated accuracy to set the margin of error auto expected_result = Approx(i + j).margin(ACCURACY); - SECTION("Fixed += Fixed") { + SECTION("PSXFixed += PSXFixed") { CHECK((double)(foo += bar) == expected_result); REQUIRE((double)foo == expected_result); } - SECTION("Fixed + Fixed") { - Fixed baz = foo + bar; + SECTION("PSXFixed + PSXFixed") { + PSXFixed baz = foo + bar; REQUIRE((double)baz == expected_result); } } diff --git a/tests/casting.cpp b/tests/casting.cpp index 3c02a29..74c308f 100644 --- a/tests/casting.cpp +++ b/tests/casting.cpp @@ -13,12 +13,12 @@ #include -#include +#include #include "config.hpp" using namespace com::saxbophone::unmoving; -using Underlying = Fixed::UnderlyingType; +using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Casting") { Underlying i = GENERATE( @@ -30,26 +30,26 @@ TEST_CASE("Casting") { ) ) ); - Fixed foo(i); + PSXFixed foo(i); - SECTION("Implicit cast Fixed to UnderlyingType") { + SECTION("Implicit cast PSXFixed to UnderlyingType") { Underlying bar = foo; REQUIRE(bar == i); } - SECTION("Explicit cast Fixed to UnderlyingType") { + SECTION("Explicit cast PSXFixed to UnderlyingType") { REQUIRE((Underlying)foo == i); } - SECTION("Explicit cast Fixed to float") { + SECTION("Explicit cast PSXFixed to float") { REQUIRE((float)foo == (float)i / 4096); } - SECTION("Explicit cast Fixed to double") { + SECTION("Explicit cast PSXFixed to double") { REQUIRE((double)foo == (double)i / 4096); } - SECTION("Fixed.to_integer()") { + SECTION("PSXFixed.to_integer()") { REQUIRE(foo.to_integer() == i / 4096); } } diff --git a/tests/comparisons.cpp b/tests/comparisons.cpp index 2d0cd04..d2d5e1a 100644 --- a/tests/comparisons.cpp +++ b/tests/comparisons.cpp @@ -11,12 +11,12 @@ */ #include -#include +#include #include "config.hpp" using namespace com::saxbophone::unmoving; -using Underlying = Fixed::UnderlyingType; +using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Comparisons") { Underlying i = GENERATE( @@ -43,26 +43,26 @@ TEST_CASE("Comparisons") { ) ); - SECTION("Fixed == Fixed") { - Fixed original(i); - Fixed same(i); // same as original - Fixed different(j); // different from original + SECTION("PSXFixed == PSXFixed") { + PSXFixed original(i); + PSXFixed same(i); // same as original + PSXFixed different(j); // different from original // check for both affirmative and negative == checks CHECK(original == same); CHECK_FALSE(original == different); } - SECTION("Fixed != Fixed") { - Fixed original(i); - Fixed same(i); // same as original - Fixed different(j); // different from original + SECTION("PSXFixed != PSXFixed") { + PSXFixed original(i); + PSXFixed same(i); // same as original + PSXFixed different(j); // different from original // check for both affirmative and negative != checks CHECK_FALSE(original != same); CHECK(original != different); } - SECTION("Fixed == UnderlyingType") { - Fixed original(i); + SECTION("PSXFixed == UnderlyingType") { + PSXFixed original(i); Underlying same = i; // same as original Underlying different = j; // different from original // check for both affirmative and negative == checks @@ -70,8 +70,8 @@ TEST_CASE("Comparisons") { CHECK_FALSE(original == different); } - SECTION("Fixed != UnderlyingType") { - Fixed original(i); + SECTION("PSXFixed != UnderlyingType") { + PSXFixed original(i); Underlying same = i; // same as original Underlying different = j; // different from original // check for both affirmative and negative == checks @@ -79,19 +79,19 @@ TEST_CASE("Comparisons") { CHECK(original != different); } - SECTION("UnderlyingType == Fixed") { + SECTION("UnderlyingType == PSXFixed") { Underlying original = i; - Fixed same(i); // same as original - Fixed different(j); // different from original + PSXFixed same(i); // same as original + PSXFixed different(j); // different from original // check for both affirmative and negative == checks CHECK(original == same); CHECK_FALSE(original == different); } - SECTION("UnderlyingType != Fixed") { + SECTION("UnderlyingType != PSXFixed") { Underlying original = i; - Fixed same(i); // same as original - Fixed different(j); // different from original + PSXFixed same(i); // same as original + PSXFixed different(j); // different from original // check for both affirmative and negative == checks CHECK_FALSE(original != same); CHECK(original != different); @@ -124,17 +124,17 @@ TEST_CASE("Comparisons") { ) ); - SECTION("Fixed < Fixed") { - Fixed smaller(i); - Fixed bigger(j); - Fixed not_bigger(k); + SECTION("PSXFixed < PSXFixed") { + PSXFixed smaller(i); + PSXFixed bigger(j); + PSXFixed not_bigger(k); // check for both affirmative and negative < checks CHECK(smaller < bigger); CHECK_FALSE(smaller < not_bigger); } - SECTION("Fixed < UnderlyingType") { - Fixed smaller(i); + SECTION("PSXFixed < UnderlyingType") { + PSXFixed smaller(i); Underlying bigger = j; Underlying not_bigger = k; // check for both affirmative and negative < checks @@ -142,10 +142,10 @@ TEST_CASE("Comparisons") { CHECK_FALSE(smaller < not_bigger); } - SECTION("UnderlyingType < Fixed") { + SECTION("UnderlyingType < PSXFixed") { Underlying smaller = i; - Fixed bigger(j); - Fixed not_bigger(k); + PSXFixed bigger(j); + PSXFixed not_bigger(k); // check for both affirmative and negative < checks CHECK(smaller < bigger); CHECK_FALSE(smaller < not_bigger); @@ -179,18 +179,18 @@ TEST_CASE("Comparisons") { ) ); - SECTION("Fixed > Fixed") { - Fixed bigger(i); - Fixed smaller(j); - Fixed not_smaller(k); + SECTION("PSXFixed > PSXFixed") { + PSXFixed bigger(i); + PSXFixed smaller(j); + PSXFixed not_smaller(k); // check for both affirmative and negative < checks CHECK(bigger > smaller); CHECK_FALSE(bigger > not_smaller); } - SECTION("Fixed > UnderlyingType") { - Fixed bigger(i); + SECTION("PSXFixed > UnderlyingType") { + PSXFixed bigger(i); Underlying smaller = j; Underlying not_smaller = k; // check for both affirmative and negative < checks @@ -199,10 +199,10 @@ TEST_CASE("Comparisons") { } - SECTION("UnderlyingType > Fixed") { + SECTION("UnderlyingType > PSXFixed") { Underlying bigger = i; - Fixed smaller(j); - Fixed not_smaller(k); + PSXFixed smaller(j); + PSXFixed not_smaller(k); // check for both affirmative and negative < checks CHECK(bigger > smaller); CHECK_FALSE(bigger > not_smaller); @@ -235,19 +235,19 @@ TEST_CASE("Comparisons") { ) ); - SECTION("Fixed <= Fixed") { - Fixed original(i); - Fixed equal(i); - Fixed bigger(j); - Fixed not_bigger_or_equal(k); + SECTION("PSXFixed <= PSXFixed") { + PSXFixed original(i); + PSXFixed equal(i); + PSXFixed bigger(j); + PSXFixed not_bigger_or_equal(k); // check for both affirmative and negative <= checks CHECK(original <= equal); CHECK(original <= bigger); CHECK_FALSE(original <= not_bigger_or_equal); } - SECTION("Fixed <= UnderlyingType") { - Fixed original(i); + SECTION("PSXFixed <= UnderlyingType") { + PSXFixed original(i); Underlying equal = i; Underlying bigger = j; Underlying not_bigger_or_equal = k; @@ -257,11 +257,11 @@ TEST_CASE("Comparisons") { CHECK_FALSE(original <= not_bigger_or_equal); } - SECTION("UnderlyingType <= Fixed") { + SECTION("UnderlyingType <= PSXFixed") { Underlying original = i; - Fixed equal(i); - Fixed bigger(j); - Fixed not_bigger_or_equal(k); + PSXFixed equal(i); + PSXFixed bigger(j); + PSXFixed not_bigger_or_equal(k); // check for both affirmative and negative <= checks CHECK(original <= equal); CHECK(original <= bigger); @@ -296,19 +296,19 @@ TEST_CASE("Comparisons") { ) ); - SECTION("Fixed >= Fixed") { - Fixed original(i); - Fixed equal(i); - Fixed smaller(j); - Fixed not_smaller_or_equal(k); + SECTION("PSXFixed >= PSXFixed") { + PSXFixed original(i); + PSXFixed equal(i); + PSXFixed smaller(j); + PSXFixed not_smaller_or_equal(k); // check for both affirmative and negative <= checks CHECK(original >= equal); CHECK(original >= smaller); CHECK_FALSE(original >= not_smaller_or_equal); } - SECTION("Fixed >= UnderlyingType") { - Fixed original(i); + SECTION("PSXFixed >= UnderlyingType") { + PSXFixed original(i); Underlying equal = i; Underlying smaller = j; Underlying not_smaller_or_equal = k; @@ -318,11 +318,11 @@ TEST_CASE("Comparisons") { CHECK_FALSE(original >= not_smaller_or_equal); } - SECTION("UnderlyingType >= Fixed") { + SECTION("UnderlyingType >= PSXFixed") { Underlying original = i; - Fixed equal(i); - Fixed smaller(j); - Fixed not_smaller_or_equal(k); + PSXFixed equal(i); + PSXFixed smaller(j); + PSXFixed not_smaller_or_equal(k); // check for both affirmative and negative <= checks CHECK(original >= equal); CHECK(original >= smaller); diff --git a/tests/constructors.cpp b/tests/constructors.cpp index 4223861..36fd78d 100644 --- a/tests/constructors.cpp +++ b/tests/constructors.cpp @@ -15,16 +15,16 @@ #include -#include +#include #include "config.hpp" using namespace com::saxbophone::unmoving; -using Underlying = Fixed::UnderlyingType; +using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Constructors") { SECTION("Default constructor can be called") { - Fixed foo = {}; + PSXFixed foo = {}; REQUIRE((Underlying)foo == 0); } @@ -40,32 +40,32 @@ TEST_CASE("Constructors") { ); SECTION("Implicit conversion from fixed-point integer") { - Fixed var = i; + PSXFixed var = i; REQUIRE((Underlying)var == i); } SECTION("Explicit conversion from fixed-point integer") { - Fixed var(i); + PSXFixed var(i); REQUIRE((Underlying)var == i); } SECTION("Special advanced constructors") { // Now for some more advanced stuff SECTION("Assignment operator can be called") { - Fixed foo, bar(i); + PSXFixed foo, bar(i); foo = bar; REQUIRE((Underlying)foo == (Underlying)bar); } SECTION("Copy constructor can be called") { - Fixed foo(i); - Fixed bar = foo; + PSXFixed foo(i); + PSXFixed bar = foo; REQUIRE((Underlying)foo == (Underlying)bar); } SECTION("Explicit copy constructor can be called") { - Fixed foo(i); - Fixed bar(foo); + PSXFixed foo(i); + PSXFixed bar(foo); REQUIRE((Underlying)foo == (Underlying)bar); } } @@ -83,13 +83,13 @@ TEST_CASE("Constructors") { ); SECTION("Implicit conversion from float") { - Fixed var = i; + PSXFixed var = i; CAPTURE(i, var, (Underlying)var, i * 4096, round(i * 4096), (Underlying)round(i * 4096)); REQUIRE((Underlying)var == (Underlying)round(i * 4096)); } SECTION("Explicit conversion from float") { - Fixed var(i); + PSXFixed var(i); REQUIRE((Underlying)var == (Underlying)round(i * 4096)); } } @@ -106,20 +106,20 @@ TEST_CASE("Constructors") { ); SECTION("Implicit conversion from double") { - Fixed var = i; + PSXFixed var = i; REQUIRE((Underlying)var == (Underlying)round(i * 4096)); } SECTION("Explicit conversion from double") { - Fixed var(i); + PSXFixed var(i); REQUIRE((Underlying)var == (Underlying)round(i * 4096)); } } SECTION("Creation from integer value") { Underlying i = GENERATE(take(tests_config::ITERATIONS, random(-524288, 524287))); - Fixed var = Fixed::from_integer(i); + PSXFixed var = PSXFixed::from_integer(i); REQUIRE((Underlying)var == i * 4096); } } diff --git a/tests/conversion_to_string.cpp b/tests/conversion_to_string.cpp index 16ed3b9..e5c7595 100644 --- a/tests/conversion_to_string.cpp +++ b/tests/conversion_to_string.cpp @@ -15,24 +15,24 @@ #include -#include +#include #include "config.hpp" using namespace com::saxbophone::unmoving; TEST_CASE("Conversion to String") { - SECTION("Fixed.to_c_str() creates a C string with the value's decimal respresentation") { + SECTION("PSXFixed.to_c_str() creates a C string with the value's decimal respresentation") { double i = GENERATE( take( tests_config::ITERATIONS, random( - Fixed::FRACTIONAL_MIN, - Fixed::FRACTIONAL_MAX + PSXFixed::FRACTIONAL_MIN, + PSXFixed::FRACTIONAL_MAX ) ) ); - Fixed var = i; + PSXFixed var = i; char output[15] = {}; // need up to 15 characters for string, including null-terminator // we require the function call to return true for successful call @@ -47,16 +47,16 @@ TEST_CASE("Conversion to String") { REQUIRE(value == Approx((double)var).margin(0.000001)); } - SECTION("Fixed.to_c_str() returns false when given buffer_size = zero") { - Fixed var; + SECTION("PSXFixed.to_c_str() returns false when given buffer_size = zero") { + PSXFixed var; char output = {}; REQUIRE_FALSE(var.to_c_str(&output, 0)); } - SECTION("Fixed.to_c_str() returns false when 1 ≤ buffer_size < 15") { + SECTION("PSXFixed.to_c_str() returns false when 1 ≤ buffer_size < 15") { std::size_t buffer_size = GENERATE(range(1U, 14U)); - Fixed var; + PSXFixed var; char* output = new char[buffer_size] {0}; REQUIRE_FALSE(var.to_c_str(output, buffer_size)); diff --git a/tests/conversion_to_string_null.cpp b/tests/conversion_to_string_null.cpp index 2dd8040..3508679 100644 --- a/tests/conversion_to_string_null.cpp +++ b/tests/conversion_to_string_null.cpp @@ -11,12 +11,12 @@ */ #include -#include +#include using namespace com::saxbophone::unmoving; -TEST_CASE("Fixed.to_c_str() returns false when buffer is a null pointer") { - Fixed var; +TEST_CASE("PSXFixed.to_c_str() returns false when buffer is a null pointer") { + PSXFixed var; // should fail because of null pointer and not buffer_size, the latter of which is big enough REQUIRE_FALSE(var.to_c_str(nullptr, 15)); diff --git a/tests/division.cpp b/tests/division.cpp index ee24fe5..c01f953 100644 --- a/tests/division.cpp +++ b/tests/division.cpp @@ -11,12 +11,12 @@ */ #include -#include +#include #include "config.hpp" using namespace com::saxbophone::unmoving; -using Underlying = Fixed::UnderlyingType; +using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Division") { double i = GENERATE( @@ -29,12 +29,12 @@ TEST_CASE("Division") { ) ); - SECTION("Division by Fixed") { + SECTION("Division by PSXFixed") { double j = GENERATE_COPY( take( 1, filter( - // verify result does not exceed bounds of Fixed type + // verify result does not exceed bounds of PSXFixed type [=](double u) { return -524288.0 <= (i / u) and (i / u) <= 524287.9997558594; @@ -47,19 +47,19 @@ TEST_CASE("Division") { ) ); - Fixed foo(i); - Fixed bar(j); - auto expected_result = Approx((double)foo / (double)bar).margin(std::pow(1.0 + Fixed::ACCURACY, 2.0) - 1.0); + PSXFixed foo(i); + PSXFixed bar(j); + auto expected_result = Approx((double)foo / (double)bar).margin(std::pow(1.0 + PSXFixed::ACCURACY, 2.0) - 1.0); - SECTION("Fixed /= Fixed") { + SECTION("PSXFixed /= PSXFixed") { CAPTURE(i, j, expected_result, (double)foo, (double)bar); CHECK((double)(foo /= bar) == expected_result); // allowed to deviate up to the smallest step in the fixed-point representation REQUIRE((double)foo == expected_result); } - SECTION("Fixed / Fixed") { - Fixed baz = foo / bar; + SECTION("PSXFixed / PSXFixed") { + PSXFixed baz = foo / bar; // allowed to deviate up to the smallest step in the fixed-point representation REQUIRE((double)baz == expected_result); } @@ -70,7 +70,7 @@ TEST_CASE("Division") { take( 1, filter( - // verify result does not exceed bounds of Fixed type + // verify result does not exceed bounds of PSXFixed type [=](Underlying u) { return -524288.0 <= (i / u) and (i / u) <= 524287.9997558594; @@ -83,18 +83,18 @@ TEST_CASE("Division") { ) ); - Fixed foo(i); + PSXFixed foo(i); Underlying bar = j; - auto expected_result = Approx((double)foo / bar).margin(std::pow(1.0 + Fixed::ACCURACY, 2.0) - 1.0); + auto expected_result = Approx((double)foo / bar).margin(std::pow(1.0 + PSXFixed::ACCURACY, 2.0) - 1.0); - SECTION("Fixed /= UnderlyingType") { + SECTION("PSXFixed /= UnderlyingType") { CHECK((double)(foo /= bar) == expected_result); // allowed to deviate up to the smallest step in the fixed-point representation REQUIRE((double)foo == expected_result); } - SECTION("Fixed / UnderlyingType") { - Fixed baz = foo / bar; + SECTION("PSXFixed / UnderlyingType") { + PSXFixed baz = foo / bar; // allowed to deviate up to the smallest step in the fixed-point representation REQUIRE((double)baz == expected_result); } diff --git a/tests/equivalences.cpp b/tests/equivalences.cpp index f4800e2..347539f 100644 --- a/tests/equivalences.cpp +++ b/tests/equivalences.cpp @@ -13,12 +13,12 @@ #include -#include +#include #include "config.hpp" using namespace com::saxbophone::unmoving; -using Underlying = Fixed::UnderlyingType; +using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Equivalences") { SECTION("Can cast from and back to raw fixed point") { @@ -31,7 +31,7 @@ TEST_CASE("Equivalences") { ) ) ); - Fixed foo = i; + PSXFixed foo = i; Underlying bar = foo; REQUIRE(bar == i); } @@ -46,9 +46,9 @@ TEST_CASE("Equivalences") { ) ) ); - Fixed var = i; + PSXFixed var = i; // allowed to deviate up to the smallest step in the fixed-point representation - REQUIRE((float)var == Approx(i).margin(Fixed::ACCURACY)); + REQUIRE((float)var == Approx(i).margin(PSXFixed::ACCURACY)); } SECTION("Can cast from and back to double") { @@ -61,14 +61,14 @@ TEST_CASE("Equivalences") { ) ) ); - Fixed var = i; + PSXFixed var = i; // allowed to deviate up to the smallest step in the fixed-point representation - REQUIRE((double)var == Approx(i).margin(Fixed::ACCURACY)); + REQUIRE((double)var == Approx(i).margin(PSXFixed::ACCURACY)); } SECTION("Can cast from and back to integer") { Underlying i = GENERATE(take(tests_config::ITERATIONS, random(-524288, 524287))); - Fixed var = Fixed::from_integer(i); + PSXFixed var = PSXFixed::from_integer(i); REQUIRE(var.to_integer() == i); } } diff --git a/tests/multiplication.cpp b/tests/multiplication.cpp index a4235b3..a1bf662 100644 --- a/tests/multiplication.cpp +++ b/tests/multiplication.cpp @@ -13,12 +13,12 @@ #include -#include +#include #include "config.hpp" using namespace com::saxbophone::unmoving; -using Underlying = Fixed::UnderlyingType; +using Underlying = PSXFixed::UnderlyingType; template constexpr double propagated_accuracy(T x, U y) { @@ -27,7 +27,7 @@ constexpr double propagated_accuracy(T x, U y) { } double z = x * y; // use standard deviation method - return std::abs(z) * std::sqrt(std::pow(Fixed::ACCURACY / x, 2.0) + std::pow(Fixed::ACCURACY / y, 2.0)); + return std::abs(z) * std::sqrt(std::pow(PSXFixed::ACCURACY / x, 2.0) + std::pow(PSXFixed::ACCURACY / y, 2.0)); } TEST_CASE("Multiplication") { @@ -41,7 +41,7 @@ TEST_CASE("Multiplication") { ) ); - SECTION("Multiplication by Fixed") { + SECTION("Multiplication by PSXFixed") { double bound_a = -524288.0 / i; double bound_b = 524287.9997558594 / i; double bound_min = std::min(bound_a, bound_b); @@ -50,11 +50,11 @@ TEST_CASE("Multiplication") { take( 1, filter( - // verify result does not exceed bounds of Fixed type + // verify result does not exceed bounds of PSXFixed type [=](double u) { - // get closest Fixed value of each operand - double x = (double)Fixed(i); - double y = (double)Fixed(u); + // get closest PSXFixed value of each operand + double x = (double)PSXFixed(i); + double y = (double)PSXFixed(u); return -524288.0 <= (x * y) and (x * y) <= 524287.9997558594; }, @@ -66,20 +66,20 @@ TEST_CASE("Multiplication") { ) ); - Fixed foo(i); - Fixed bar(j); + PSXFixed foo(i); + PSXFixed bar(j); // calculate propagated accuracy error based on operands auto expected_result = Approx((double)foo * (double)bar).margin(propagated_accuracy(i, j)); - SECTION("Fixed *= Fixed") { + SECTION("PSXFixed *= PSXFixed") { CAPTURE(i, j, expected_result, (double)foo, (double)bar); CHECK((double)(foo *= bar) == expected_result); REQUIRE((double)foo == expected_result); } - SECTION("Fixed * Fixed") { - Fixed baz = foo * bar; + SECTION("PSXFixed * PSXFixed") { + PSXFixed baz = foo * bar; REQUIRE((double)baz == expected_result); } } @@ -93,7 +93,7 @@ TEST_CASE("Multiplication") { take( 1, filter( - // verify result does not exceed bounds of Fixed type + // verify result does not exceed bounds of PSXFixed type [=](Underlying u) { return -524288.0 <= (i * u) and (i * u) <= 524287.9997558594; @@ -106,23 +106,23 @@ TEST_CASE("Multiplication") { ) ); - Fixed foo(i); + PSXFixed foo(i); Underlying bar = j; // calculate propagated accuracy error based on operands auto expected_result = Approx((double)foo * bar).margin(propagated_accuracy(i, j)); - SECTION("Fixed *= UnderlyingType") { + SECTION("PSXFixed *= UnderlyingType") { CHECK((double)(foo *= bar) == expected_result); REQUIRE((double)foo == expected_result); } - SECTION("Fixed * UnderlyingType") { - Fixed baz = foo * bar; + SECTION("PSXFixed * UnderlyingType") { + PSXFixed baz = foo * bar; REQUIRE((double)baz == expected_result); } - SECTION("UnderlyingType * Fixed") { - Fixed baz = bar * foo; + SECTION("UnderlyingType * PSXFixed") { + PSXFixed baz = bar * foo; REQUIRE((double)baz == expected_result); } diff --git a/tests/static_checks.cpp b/tests/static_checks.cpp index 520435a..4d624d8 100644 --- a/tests/static_checks.cpp +++ b/tests/static_checks.cpp @@ -17,144 +17,144 @@ #define CATCH_CONFIG_RUNTIME_STATIC_REQUIRE #include -#include +#include #include "config.hpp" -// various static (compile-time) checks on properties of Fixed class +// various static (compile-time) checks on properties of PSXFixed class using namespace com::saxbophone::unmoving; -using Underlying = Fixed::UnderlyingType; +using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Static Checks") { - SECTION("Fixed::UnderlyingType is integral") { + SECTION("PSXFixed::UnderlyingType is integral") { STATIC_REQUIRE(std::is_integral_v); } - SECTION("Fixed::UnderlyingType has more bits than Fixed::FRACTION_BITS") { - STATIC_REQUIRE(std::numeric_limits::digits > Fixed::FRACTION_BITS); + SECTION("PSXFixed::UnderlyingType has more bits than PSXFixed::FRACTION_BITS") { + STATIC_REQUIRE(std::numeric_limits::digits > PSXFixed::FRACTION_BITS); } - SECTION("Fixed::UnderlyingType has more bits than Fixed::DECIMAL_BITS") { - STATIC_REQUIRE(std::numeric_limits::digits > Fixed::DECIMAL_BITS); + SECTION("PSXFixed::UnderlyingType has more bits than PSXFixed::DECIMAL_BITS") { + STATIC_REQUIRE(std::numeric_limits::digits > PSXFixed::DECIMAL_BITS); } - SECTION("Fixed::SCALE == 2 ** Fixed::FRACTION_BITS") { - STATIC_REQUIRE(Fixed::SCALE == 1 << Fixed::FRACTION_BITS); + SECTION("PSXFixed::SCALE == 2 ** PSXFixed::FRACTION_BITS") { + STATIC_REQUIRE(PSXFixed::SCALE == 1 << PSXFixed::FRACTION_BITS); } - SECTION("Fixed::DECIMAL_BITS == Fixed::UnderlyingType bits - Fixed::FRACTION_BITS") { - STATIC_REQUIRE(Fixed::DECIMAL_BITS == std::numeric_limits::digits - Fixed::FRACTION_BITS); + SECTION("PSXFixed::DECIMAL_BITS == PSXFixed::UnderlyingType bits - PSXFixed::FRACTION_BITS") { + STATIC_REQUIRE(PSXFixed::DECIMAL_BITS == std::numeric_limits::digits - PSXFixed::FRACTION_BITS); } - SECTION("Fixed::PRECISION == 1 / Fixed::SCALE") { - STATIC_REQUIRE(Fixed::PRECISION == Approx(1.0 / Fixed::SCALE)); + SECTION("PSXFixed::PRECISION == 1 / PSXFixed::SCALE") { + STATIC_REQUIRE(PSXFixed::PRECISION == Approx(1.0 / PSXFixed::SCALE)); } - SECTION("Fixed::ACCURACY == Fixed::PRECISION / 2") { - STATIC_REQUIRE(Fixed::ACCURACY == Fixed::PRECISION / 2.0); + SECTION("PSXFixed::ACCURACY == PSXFixed::PRECISION / 2") { + STATIC_REQUIRE(PSXFixed::ACCURACY == PSXFixed::PRECISION / 2.0); } - SECTION("Fixed::DECIMAL_MAX == 2 ** Fixed::DECIMAL_BITS - 1") { - STATIC_REQUIRE(Fixed::DECIMAL_MAX == (1 << Fixed::DECIMAL_BITS) - 1); + SECTION("PSXFixed::DECIMAL_MAX == 2 ** PSXFixed::DECIMAL_BITS - 1") { + STATIC_REQUIRE(PSXFixed::DECIMAL_MAX == (1 << PSXFixed::DECIMAL_BITS) - 1); } - SECTION("Fixed::DECIMAL_MIN == -(2 ** Fixed::DECIMAL_BITS)") { - STATIC_REQUIRE(Fixed::DECIMAL_MIN == -(1 << Fixed::DECIMAL_BITS)); + SECTION("PSXFixed::DECIMAL_MIN == -(2 ** PSXFixed::DECIMAL_BITS)") { + STATIC_REQUIRE(PSXFixed::DECIMAL_MIN == -(1 << PSXFixed::DECIMAL_BITS)); } - SECTION("Fixed::FRACTIONAL_MAX == Fixed::DECIMAL_MAX + (1 - Fixed::PRECISION)") { - STATIC_REQUIRE(Fixed::FRACTIONAL_MAX == Fixed::DECIMAL_MAX + (1.0 - Fixed::PRECISION)); + SECTION("PSXFixed::FRACTIONAL_MAX == PSXFixed::DECIMAL_MAX + (1 - PSXFixed::PRECISION)") { + STATIC_REQUIRE(PSXFixed::FRACTIONAL_MAX == PSXFixed::DECIMAL_MAX + (1.0 - PSXFixed::PRECISION)); } - SECTION("Fixed::FRACTIONAL_MIN == Fixed::DECIMAL_MIN") { - STATIC_REQUIRE(Fixed::FRACTIONAL_MIN == Fixed::DECIMAL_MIN); + SECTION("PSXFixed::FRACTIONAL_MIN == PSXFixed::DECIMAL_MIN") { + STATIC_REQUIRE(PSXFixed::FRACTIONAL_MIN == PSXFixed::DECIMAL_MIN); } - SECTION("Fixed::MAX() == Max 32-bit signed integer") { - STATIC_REQUIRE(Fixed::MAX() == Fixed(std::numeric_limits::max())); + SECTION("PSXFixed::MAX() == Max 32-bit signed integer") { + STATIC_REQUIRE(PSXFixed::MAX() == PSXFixed(std::numeric_limits::max())); } - SECTION("Fixed::MIN() == Min 32-bit signed integer") { - STATIC_REQUIRE(Fixed::MIN() == Fixed(std::numeric_limits::min())); + SECTION("PSXFixed::MIN() == Min 32-bit signed integer") { + STATIC_REQUIRE(PSXFixed::MIN() == PSXFixed(std::numeric_limits::min())); } - SECTION("typeof(Fixed::MAX()) == Fixed") { - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed::MAX()) == PSXFixed") { + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed::MIN()) == Fixed") { - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed::MIN()) == PSXFixed") { + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed + Fixed) == Fixed") { - Fixed x = {}, y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed + PSXFixed) == PSXFixed") { + PSXFixed x = {}, y = {}; + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed += Fixed) == Fixed&") { - Fixed x = {}, y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed += PSXFixed) == PSXFixed&") { + PSXFixed x = {}, y = {}; + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed - Fixed) == Fixed") { - Fixed x = {}, y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed - PSXFixed) == PSXFixed") { + PSXFixed x = {}, y = {}; + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed -= Fixed) == Fixed&") { - Fixed x = {}, y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed -= PSXFixed) == PSXFixed&") { + PSXFixed x = {}, y = {}; + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed * Fixed) == Fixed") { - Fixed x = {}, y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed * PSXFixed) == PSXFixed") { + PSXFixed x = {}, y = {}; + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed *= Fixed) == Fixed&") { - Fixed x = {}, y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed *= PSXFixed) == PSXFixed&") { + PSXFixed x = {}, y = {}; + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed * UnderlyingType) == Fixed") { - Fixed x = {}; - Fixed::UnderlyingType y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed * UnderlyingType) == PSXFixed") { + PSXFixed x = {}; + PSXFixed::UnderlyingType y = {}; + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed *= UnderlyingType) == Fixed&") { - Fixed x = {}; - Fixed::UnderlyingType y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed *= UnderlyingType) == PSXFixed&") { + PSXFixed x = {}; + PSXFixed::UnderlyingType y = {}; + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(UnderlyingType * Fixed) == Fixed") { - Fixed::UnderlyingType x = {}; - Fixed y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(UnderlyingType * PSXFixed) == PSXFixed") { + PSXFixed::UnderlyingType x = {}; + PSXFixed y = {}; + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed / Fixed) == Fixed") { - Fixed x = {}, y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed / PSXFixed) == PSXFixed") { + PSXFixed x = {}, y = {}; + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed /= Fixed) == Fixed&") { - Fixed x = {}, y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed /= PSXFixed) == PSXFixed&") { + PSXFixed x = {}, y = {}; + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed / UnderlyingType) == Fixed") { - Fixed x = {}; - Fixed::UnderlyingType y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed / UnderlyingType) == PSXFixed") { + PSXFixed x = {}; + PSXFixed::UnderlyingType y = {}; + STATIC_REQUIRE(std::is_same_v); } - SECTION("typeof(Fixed /= UnderlyingType) == Fixed&") { - Fixed x = {}; - Fixed::UnderlyingType y = {}; - STATIC_REQUIRE(std::is_same_v); + SECTION("typeof(PSXFixed /= UnderlyingType) == PSXFixed&") { + PSXFixed x = {}; + PSXFixed::UnderlyingType y = {}; + STATIC_REQUIRE(std::is_same_v); } } diff --git a/tests/subtraction.cpp b/tests/subtraction.cpp index 04165ec..05344dd 100644 --- a/tests/subtraction.cpp +++ b/tests/subtraction.cpp @@ -16,23 +16,23 @@ #include -#include +#include #include "config.hpp" using namespace com::saxbophone::unmoving; -using Underlying = Fixed::UnderlyingType; +using Underlying = PSXFixed::UnderlyingType; // calculated propagated accuracy error after a subtraction -constexpr double ACCURACY = Fixed::ACCURACY * 2.0; +constexpr double ACCURACY = PSXFixed::ACCURACY * 2.0; TEST_CASE("Subtraction") { double i = GENERATE( take( tests_config::ITERATIONS, random( - Fixed::FRACTIONAL_MIN, - Fixed::FRACTIONAL_MAX + PSXFixed::FRACTIONAL_MIN, + PSXFixed::FRACTIONAL_MAX ) ) ); @@ -43,28 +43,28 @@ TEST_CASE("Subtraction") { filter( [=](double u) { auto sum = i - u; - return Fixed::FRACTIONAL_MIN <= sum and - sum <= Fixed::FRACTIONAL_MAX; + return PSXFixed::FRACTIONAL_MIN <= sum and + sum <= PSXFixed::FRACTIONAL_MAX; }, random( - Fixed::FRACTIONAL_MIN, - Fixed::FRACTIONAL_MAX + PSXFixed::FRACTIONAL_MIN, + PSXFixed::FRACTIONAL_MAX ) ) ) ); - Fixed foo(i); - Fixed bar(j); + PSXFixed foo(i); + PSXFixed bar(j); // use calculated accuracy to set the margin of error auto expected_result = Approx(i - j).margin(ACCURACY); - SECTION("Fixed -= Fixed") { + SECTION("PSXFixed -= PSXFixed") { CHECK((double)(foo -= bar) == expected_result); REQUIRE((double)foo == expected_result); } - SECTION("Fixed - Fixed") { - Fixed baz = foo - bar; + SECTION("PSXFixed - PSXFixed") { + PSXFixed baz = foo - bar; REQUIRE((double)baz == expected_result); } } diff --git a/tests/unary_operations.cpp b/tests/unary_operations.cpp index 8827e26..a616fbf 100644 --- a/tests/unary_operations.cpp +++ b/tests/unary_operations.cpp @@ -11,15 +11,15 @@ */ #include -#include +#include #include "config.hpp" using namespace com::saxbophone::unmoving; -using Underlying = Fixed::UnderlyingType; +using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Unary operations") { - SECTION("Fixed prefix increment") { + SECTION("PSXFixed prefix increment") { double i = GENERATE( take( tests_config::ITERATIONS, @@ -30,13 +30,13 @@ TEST_CASE("Unary operations") { ) ) ); - Fixed foo(i); - Fixed bar = ++foo; - REQUIRE((double)bar == Approx(++i).margin(Fixed::ACCURACY)); - REQUIRE((double)foo == Approx(i).margin(Fixed::ACCURACY)); // relies upon i value changed in previous check + PSXFixed foo(i); + PSXFixed bar = ++foo; + REQUIRE((double)bar == Approx(++i).margin(PSXFixed::ACCURACY)); + REQUIRE((double)foo == Approx(i).margin(PSXFixed::ACCURACY)); // relies upon i value changed in previous check } - SECTION("Fixed postfix increment") { + SECTION("PSXFixed postfix increment") { double i = GENERATE( take( tests_config::ITERATIONS, @@ -47,13 +47,13 @@ TEST_CASE("Unary operations") { ) ) ); - Fixed foo(i); - Fixed bar = foo++; - REQUIRE((double)bar == Approx(i++).margin(Fixed::ACCURACY)); - REQUIRE((double)foo == Approx(i).margin(Fixed::ACCURACY)); // relies upon i value changed in previous check + PSXFixed foo(i); + PSXFixed bar = foo++; + REQUIRE((double)bar == Approx(i++).margin(PSXFixed::ACCURACY)); + REQUIRE((double)foo == Approx(i).margin(PSXFixed::ACCURACY)); // relies upon i value changed in previous check } - SECTION("Fixed prefix decrement") { + SECTION("PSXFixed prefix decrement") { double i = GENERATE( take( tests_config::ITERATIONS, @@ -64,13 +64,13 @@ TEST_CASE("Unary operations") { ) ) ); - Fixed foo(i); - Fixed bar = --foo; - REQUIRE((double)bar == Approx(--i).margin(Fixed::ACCURACY)); - REQUIRE((double)foo == Approx(i).margin(Fixed::ACCURACY)); // relies upon i value changed in previous check + PSXFixed foo(i); + PSXFixed bar = --foo; + REQUIRE((double)bar == Approx(--i).margin(PSXFixed::ACCURACY)); + REQUIRE((double)foo == Approx(i).margin(PSXFixed::ACCURACY)); // relies upon i value changed in previous check } - SECTION("Fixed postfix decrement") { + SECTION("PSXFixed postfix decrement") { double i = GENERATE( take( tests_config::ITERATIONS, @@ -81,13 +81,13 @@ TEST_CASE("Unary operations") { ) ) ); - Fixed foo(i); - Fixed bar = foo--; - REQUIRE((double)bar == Approx(i--).margin(Fixed::ACCURACY)); - REQUIRE((double)foo == Approx(i).margin(Fixed::ACCURACY)); // relies upon i value changed in previous check + PSXFixed foo(i); + PSXFixed bar = foo--; + REQUIRE((double)bar == Approx(i--).margin(PSXFixed::ACCURACY)); + REQUIRE((double)foo == Approx(i).margin(PSXFixed::ACCURACY)); // relies upon i value changed in previous check } - SECTION("Fixed unary minus") { + SECTION("PSXFixed unary minus") { Underlying i = GENERATE( take( tests_config::ITERATIONS, @@ -97,8 +97,8 @@ TEST_CASE("Unary operations") { ) ) ); - Fixed foo(i); - Fixed bar = -foo; + PSXFixed foo(i); + PSXFixed bar = -foo; // this should be an exact conversion, so comparing for exact equality is fine REQUIRE((double)bar == -((double)foo)); } diff --git a/tests/user_defined_literals.cpp b/tests/user_defined_literals.cpp index e18a7d2..96e27b6 100644 --- a/tests/user_defined_literals.cpp +++ b/tests/user_defined_literals.cpp @@ -11,7 +11,7 @@ */ #include -#include +#include #include "config.hpp" @@ -26,39 +26,39 @@ using namespace com::saxbophone::unmoving; TEST_CASE("User-defined literals") { SECTION("Full user-defined literal") { - auto literal_to_value = GENERATE(table({ + auto literal_to_value = GENERATE(table({ {123.45_fx, 123.45,}, {123.456789_fx, 123.456789,}, {0.317282_fx, 0.317282,}, {456128.33937921009_fx, 456128.33937921009,}, })); - Fixed foo = std::get(literal_to_value); - CAPTURE(std::get(literal_to_value), std::get(literal_to_value)); + PSXFixed foo = std::get(literal_to_value); + CAPTURE(std::get(literal_to_value), std::get(literal_to_value)); // allowed to deviate up to the smallest step in the fixed-point representation - REQUIRE((double)foo == Approx(std::get(literal_to_value)).margin(Fixed::ACCURACY)); + REQUIRE((double)foo == Approx(std::get(literal_to_value)).margin(PSXFixed::ACCURACY)); } SECTION("Fractional user-defined literal") { - auto literal_to_value = GENERATE(table({ + auto literal_to_value = GENERATE(table({ {.45_fx, .45,}, {.456789_fx, .456789,}, {.317282_fx, .317282,}, {.33937921009_fx, .33937921009,}, })); - Fixed foo = std::get(literal_to_value); + PSXFixed foo = std::get(literal_to_value); // allowed to deviate up to the smallest step in the fixed-point representation - REQUIRE((double)foo == Approx(std::get(literal_to_value)).margin(Fixed::ACCURACY)); + REQUIRE((double)foo == Approx(std::get(literal_to_value)).margin(PSXFixed::ACCURACY)); } SECTION("Integral user-defined literal") { - auto literal_to_value = GENERATE(table({ + auto literal_to_value = GENERATE(table({ {12345_fx, 12345.0,}, {123456_fx, 123456.0,}, {317282_fx, 317282.0,}, {456128_fx, 456128.0,}, })); - Fixed foo = std::get(literal_to_value); + PSXFixed foo = std::get(literal_to_value); // allowed to deviate up to the smallest step in the fixed-point representation - REQUIRE((double)foo == Approx(std::get(literal_to_value)).margin(Fixed::ACCURACY)); + REQUIRE((double)foo == Approx(std::get(literal_to_value)).margin(PSXFixed::ACCURACY)); } } diff --git a/unmoving/include/unmoving/Fixed.hpp b/unmoving/include/unmoving/PSXFixed.hpp similarity index 69% rename from unmoving/include/unmoving/Fixed.hpp rename to unmoving/include/unmoving/PSXFixed.hpp index b1e5c9d..acb7686 100644 --- a/unmoving/include/unmoving/Fixed.hpp +++ b/unmoving/include/unmoving/PSXFixed.hpp @@ -10,7 +10,7 @@ * @warning Performance testing has not been done either in emulators or real * PlayStation hardware. Although effort has been made to make this code * efficient, at this stage this cannot be guaranteed, particularly with - * multiplication or division between two Fixed instances. + * multiplication or division between two PSXFixed instances. * * @author Joshua Saxby * @date September 2021 @@ -23,8 +23,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef COM_SAXBOPHONE_UNMOVING_UNMOVING_HPP -#define COM_SAXBOPHONE_UNMOVING_UNMOVING_HPP +#ifndef COM_SAXBOPHONE_UNMOVING_PSX_FIXED_HPP +#define COM_SAXBOPHONE_UNMOVING_PSX_FIXED_HPP // NOTE: Blindly assuming that the PS1 environment declares itself as a freestanding implementation for this check! #if __STDC_HOSTED__ @@ -37,83 +37,83 @@ #include // abs namespace com::saxbophone::unmoving { - class Fixed; // forward-declaration to allow declaration of user-defined literals + class PSXFixed; // forward-declaration to allow declaration of user-defined literals /** - * @brief User-defined literal for Fixed objects with fractional parts + * @brief User-defined literal for PSXFixed objects with fractional parts * * @b Usage: * @code - * Fixed full = 123.45_fx; - * Fixed fractional = .45_fx; + * PSXFixed full = 123.45_fx; + * PSXFixed fractional = .45_fx; * @endcode - * @relatedalso Fixed + * @relatedalso PSXFixed */ - constexpr Fixed operator"" _fx(long double literal); + constexpr PSXFixed operator"" _fx(long double literal); /** - * @brief User-defined literal for Fixed objects without fractional parts + * @brief User-defined literal for PSXFixed objects without fractional parts * * @b Usage: * @code - * Fixed integral = 123_fx; + * PSXFixed integral = 123_fx; * @endcode - * @warning Use this to initialise Fixed objects when the intention is + * @warning Use this to initialise PSXFixed objects when the intention is * to hold the same value as the integer. Use regular integer literals * when the intention is to interpret the integer as a fixed-point value * (this is the fixed-point equivalent of initialising a float from raw * memory values). - * @relatedalso Fixed + * @relatedalso PSXFixed */ - constexpr Fixed operator"" _fx(unsigned long long int literal); + constexpr PSXFixed operator"" _fx(unsigned long long int literal); /** - * @brief Fixed-point arithmetic value type for Sony PlayStation + * @brief PSXFixed-point arithmetic value type for Sony PlayStation * @details Wraps the native 32-bit integers used on the platform for fixed * point arithmetic and allows arithmetic operations to be done on these * instances directly, handling the additional arithmetic for emulating * fixed-point internally. * @todo Document constants */ - class Fixed { + class PSXFixed { public: using UnderlyingType = int32_t; static constexpr size_t FRACTION_BITS = 12; static constexpr size_t DECIMAL_BITS = 19; - static constexpr UnderlyingType SCALE = 1 << Fixed::FRACTION_BITS; + static constexpr UnderlyingType SCALE = 1 << PSXFixed::FRACTION_BITS; // precision is the closeness of different values to eachother - static constexpr double PRECISION = 1.0 / Fixed::SCALE; + static constexpr double PRECISION = 1.0 / PSXFixed::SCALE; // accuracy is closeness of a value to the "true" value - static constexpr double ACCURACY = Fixed::PRECISION / 2.0; - static constexpr UnderlyingType DECIMAL_MAX = (1 << Fixed::DECIMAL_BITS) - 1; - static constexpr UnderlyingType DECIMAL_MIN = -(1 << Fixed::DECIMAL_BITS); - static constexpr double FRACTIONAL_MAX = Fixed::DECIMAL_MAX + (1.0 - Fixed::PRECISION); - static constexpr double FRACTIONAL_MIN = Fixed::DECIMAL_MIN; + static constexpr double ACCURACY = PSXFixed::PRECISION / 2.0; + static constexpr UnderlyingType DECIMAL_MAX = (1 << PSXFixed::DECIMAL_BITS) - 1; + static constexpr UnderlyingType DECIMAL_MIN = -(1 << PSXFixed::DECIMAL_BITS); + static constexpr double FRACTIONAL_MAX = PSXFixed::DECIMAL_MAX + (1.0 - PSXFixed::PRECISION); + static constexpr double FRACTIONAL_MIN = PSXFixed::DECIMAL_MIN; - static constexpr Fixed MAX() { - return Fixed((UnderlyingType)2147483647); + static constexpr PSXFixed MAX() { + return PSXFixed((UnderlyingType)2147483647); } - static constexpr Fixed MIN() { - return Fixed((UnderlyingType)-2147483648); + static constexpr PSXFixed MIN() { + return PSXFixed((UnderlyingType)-2147483648); } /** - * @brief Default constructor, creates a Fixed instance with value `0.0_fx` + * @brief Default constructor, creates a PSXFixed instance with value `0.0_fx` */ - constexpr Fixed() : _raw_value(0) {} + constexpr PSXFixed() : _raw_value(0) {} /** * @brief Implicit converting constructor from fixed-point integer - * @details Creates a Fixed instance wrapping a raw fixed-point integer, + * @details Creates a PSXFixed instance wrapping a raw fixed-point integer, * of the kind used by the PlayStation SDK functions. - * @warning Don't use this for converting plain integers into Fixed. - * Use Fixed::from_integer for that. - * @see Fixed::from_integer + * @warning Don't use this for converting plain integers into PSXFixed. + * Use PSXFixed::from_integer for that. + * @see PSXFixed::from_integer */ - constexpr Fixed(UnderlyingType raw_value) : _raw_value(raw_value) {} + constexpr PSXFixed(UnderlyingType raw_value) : _raw_value(raw_value) {} /** * @brief Implicit converting constructor from float/double - * @details Creates a Fixed instance with the nearest fixed-point value + * @details Creates a PSXFixed instance with the nearest fixed-point value * to the given floating point value. * @warning This loses precision. * @note Not recommended to use this outside of constexpr contexts @@ -123,8 +123,8 @@ namespace com::saxbophone::unmoving { * methodfor faster emulation when doing runtime conversions on the * PlayStation and `double` precision is not needed. */ - constexpr Fixed(double value) { - double scaled = value * Fixed::SCALE; + constexpr PSXFixed(double value) { + double scaled = value * PSXFixed::SCALE; // separate into integer and fraction so we can round the fraction UnderlyingType integral = (UnderlyingType)scaled; double remainder = scaled - integral; @@ -135,15 +135,15 @@ namespace com::saxbophone::unmoving { this->_raw_value = integral; } /** - * @returns a Fixed instance representing the closest fixed-point value + * @returns a PSXFixed instance representing the closest fixed-point value * to the given integer value. - * @warning Don't use this for converting raw fixed-point integers to Fixed. - * Use Fixed::Fixed(UnderlyingType) for that. - * @see Fixed::Fixed(UnderlyingType) + * @warning Don't use this for converting raw fixed-point integers to PSXFixed. + * Use PSXFixed::PSXFixed(UnderlyingType) for that. + * @see PSXFixed::PSXFixed(UnderlyingType) * @todo Check for overflow? No exceptions on the PS1... */ - static constexpr Fixed from_integer(int value) { - return Fixed(value << Fixed::FRACTION_BITS); + static constexpr PSXFixed from_integer(int value) { + return PSXFixed(value << PSXFixed::FRACTION_BITS); } /** * @brief Implicit cast operator to underlying type @@ -153,15 +153,15 @@ namespace com::saxbophone::unmoving { } /** * @brief Explicit cast operator to double - * @details Returns exact value of this Fixed instance as double-precision floating point + * @details Returns exact value of this PSXFixed instance as double-precision floating point * @note There is enough precision in double-precision IEEE floats to - * exactly represent all Fixed point values. + * exactly represent all PSXFixed point values. * @note Not recommended to use this outside of constexpr contexts * where avoidable on the PlayStation, as the console has no hardware * floating point support, so slow software floats will be used. */ explicit constexpr operator double() const { - return (double)this->_raw_value / Fixed::SCALE; + return (double)this->_raw_value / PSXFixed::SCALE; } /** * @brief Explicit cast operator to float @@ -179,14 +179,14 @@ namespace com::saxbophone::unmoving { return (float)(double)*this; } /** - * @returns Fixed-point value converted to integer, with fractional part truncated. + * @returns PSXFixed-point value converted to integer, with fractional part truncated. */ constexpr UnderlyingType to_integer() const { // can't use a right-shift here due to it not handling negative values properly - return this->_raw_value / Fixed::SCALE; + return this->_raw_value / PSXFixed::SCALE; } /** - * @brief Stringifies the Fixed-point value to a C-string + * @brief Stringifies the PSXFixed-point value to a C-string * @param buffer pointer to array of `char`. Must be non-null and pointing to buffer of size `buffer_size`. * @param[out] buffer_size size of `buffer`. Should be at least `15`. * @returns `false` if buffer could not be written, because buffer_size wasn't big enough @@ -216,44 +216,44 @@ namespace com::saxbophone::unmoving { /** * @brief Prefix increment operator */ - constexpr Fixed& operator++() { - *this += Fixed::SCALE; + constexpr PSXFixed& operator++() { + *this += PSXFixed::SCALE; return *this; } /** * @brief Prefix decrement operator */ - constexpr Fixed& operator--() { - *this -= Fixed::SCALE; + constexpr PSXFixed& operator--() { + *this -= PSXFixed::SCALE; return *this; } /** * @brief Postfix increment operator */ - constexpr Fixed operator++(int) { - Fixed old = *this; // copy old value + constexpr PSXFixed operator++(int) { + PSXFixed old = *this; // copy old value ++*this; // prefix increment return old; // return old value } /** * @brief Postfix decrement operator */ - constexpr Fixed operator--(int) { - Fixed old = *this; // copy old value + constexpr PSXFixed operator--(int) { + PSXFixed old = *this; // copy old value --*this; // prefix decrement return old; // return old value } /** * @brief Compound assignment addition operator */ - constexpr Fixed& operator +=(const Fixed& rhs) { + constexpr PSXFixed& operator +=(const PSXFixed& rhs) { this->_raw_value += rhs._raw_value; return *this; } /** * @brief Compound assignment subtraction operator */ - constexpr Fixed& operator -=(const Fixed& rhs) { + constexpr PSXFixed& operator -=(const PSXFixed& rhs) { this->_raw_value -= rhs._raw_value; return *this; } @@ -265,18 +265,18 @@ namespace com::saxbophone::unmoving { * assembly to take advantage of the R3000's 64-bit double-word multiply * feature. */ - constexpr Fixed& operator *=(const Fixed& rhs) { + constexpr PSXFixed& operator *=(const PSXFixed& rhs) { // XXX: no int64_t on PS1, software emulation kicks in automatically int64_t result = (int64_t)this->_raw_value * rhs._raw_value; // shift back down - this->_raw_value = (UnderlyingType)(result / Fixed::SCALE); + this->_raw_value = (UnderlyingType)(result / PSXFixed::SCALE); return *this; } /** * @brief Compound assignment integer multiplication operator * @todo Investigate overflow? */ - constexpr Fixed& operator *=(const UnderlyingType& rhs) { + constexpr PSXFixed& operator *=(const UnderlyingType& rhs) { this->_raw_value *= rhs; return *this; } @@ -288,9 +288,9 @@ namespace com::saxbophone::unmoving { * assembly to take advantage of the R3000's 64-bit double-word multiply * feature. */ - constexpr Fixed& operator /=(const Fixed& rhs) { + constexpr PSXFixed& operator /=(const PSXFixed& rhs) { // XXX: no int64_t on PS1, software emulation kicks in automatically - int64_t scaled = (int64_t)this->_raw_value * Fixed::SCALE; + int64_t scaled = (int64_t)this->_raw_value * PSXFixed::SCALE; this->_raw_value = (UnderlyingType)(scaled / rhs._raw_value); return *this; } @@ -298,61 +298,61 @@ namespace com::saxbophone::unmoving { * @brief Compound assignment integer division operator * @todo Investigate overflow? */ - constexpr Fixed& operator /=(const UnderlyingType& rhs) { + constexpr PSXFixed& operator /=(const UnderlyingType& rhs) { this->_raw_value /= rhs; return *this; } /** * @brief Unary minus (negation) operator */ - constexpr Fixed operator-() const { - return Fixed(-this->_raw_value); + constexpr PSXFixed operator-() const { + return PSXFixed(-this->_raw_value); } /** * @brief Addition operator */ - constexpr friend Fixed operator+(Fixed lhs, const Fixed& rhs) { + constexpr friend PSXFixed operator+(PSXFixed lhs, const PSXFixed& rhs) { lhs += rhs; return lhs; } /** * @brief Subtraction operator */ - constexpr friend Fixed operator-(Fixed lhs, const Fixed& rhs) { + constexpr friend PSXFixed operator-(PSXFixed lhs, const PSXFixed& rhs) { lhs -= rhs; return lhs; } /** * @brief Multiplication operator */ - constexpr friend Fixed operator*(Fixed lhs, const Fixed& rhs) { + constexpr friend PSXFixed operator*(PSXFixed lhs, const PSXFixed& rhs) { lhs *= rhs; return lhs; } /** * @brief Integer multiplication operator */ - constexpr friend Fixed operator*(Fixed lhs, const UnderlyingType& rhs) { + constexpr friend PSXFixed operator*(PSXFixed lhs, const UnderlyingType& rhs) { lhs *= rhs; return lhs; } /** * @brief Integer multiplication operator */ - constexpr friend Fixed operator*(UnderlyingType lhs, const Fixed& rhs) { + constexpr friend PSXFixed operator*(UnderlyingType lhs, const PSXFixed& rhs) { return rhs * lhs; } /** * @brief Division operator */ - constexpr friend Fixed operator/(Fixed lhs, const Fixed& rhs) { + constexpr friend PSXFixed operator/(PSXFixed lhs, const PSXFixed& rhs) { lhs /= rhs; return lhs; } /** * @brief Integer division operator */ - constexpr friend Fixed operator/(Fixed lhs, const UnderlyingType& rhs) { + constexpr friend PSXFixed operator/(PSXFixed lhs, const UnderlyingType& rhs) { lhs /= rhs; return lhs; } @@ -361,12 +361,12 @@ namespace com::saxbophone::unmoving { UnderlyingType _raw_value; }; - constexpr Fixed operator"" _fx(long double literal) { - return Fixed((double)literal); + constexpr PSXFixed operator"" _fx(long double literal) { + return PSXFixed((double)literal); } - constexpr Fixed operator"" _fx(unsigned long long int literal) { - return Fixed::from_integer((Fixed::UnderlyingType)literal); + constexpr PSXFixed operator"" _fx(unsigned long long int literal) { + return PSXFixed::from_integer((PSXFixed::UnderlyingType)literal); } } From 599687eca068961259df5f6500fdf7849de0d738 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 06:16:41 +0100 Subject: [PATCH 05/18] Documented undocumented members --- unmoving/include/unmoving/PSXFixed.hpp | 64 +++++++++++++++++++++----- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/unmoving/include/unmoving/PSXFixed.hpp b/unmoving/include/unmoving/PSXFixed.hpp index acb7686..0d25035 100644 --- a/unmoving/include/unmoving/PSXFixed.hpp +++ b/unmoving/include/unmoving/PSXFixed.hpp @@ -26,13 +26,18 @@ #ifndef COM_SAXBOPHONE_UNMOVING_PSX_FIXED_HPP #define COM_SAXBOPHONE_UNMOVING_PSX_FIXED_HPP -// NOTE: Blindly assuming that the PS1 environment declares itself as a freestanding implementation for this check! +// we can get int32 and size_t from the C++ standard library when build is hosted #if __STDC_HOSTED__ -#include -#include +#include // size_t +#include // int32 #else -#include +// NOTE: this C header is specific to the PSX SDK +#include // int32, size_t #endif +/* + * get other symbols from the C headers as these are guaranteed to exist both in + * C++ and the PSX SDK + */ #include // snprintf #include // abs @@ -73,31 +78,65 @@ namespace com::saxbophone::unmoving { * point arithmetic and allows arithmetic operations to be done on these * instances directly, handling the additional arithmetic for emulating * fixed-point internally. - * @todo Document constants + * @note The fixed-point integers implemented by this type match those + * handled by the PSX standard library, which are `Q19.12` numbers when + * specified in Q Notation (https://en.wikipedia.org/wiki/Q_(number_format)) */ class PSXFixed { public: + /** + * @brief Underlying base type the fixed-point integer is stored as + * @details Should be `int32` or `int` to match the type used by PSX + * standard library in its fixed-point maths routines. + */ using UnderlyingType = int32_t; - static constexpr size_t FRACTION_BITS = 12; + /** @brief How many bits are used for the integer part of the fixed-point integer */ static constexpr size_t DECIMAL_BITS = 19; + /** @brief How many bits are used for the fraction part of the fixed-point integer */ + static constexpr size_t FRACTION_BITS = 12; + /** + * @brief The scale used for the fixed-point integer + * @note This matches the scale used by the PSX standard library for + * fixed-point arithmetic, which uses a scale of 4096 (macro: `ONE`). + */ static constexpr UnderlyingType SCALE = 1 << PSXFixed::FRACTION_BITS; - // precision is the closeness of different values to eachother + /** + * @brief How far apart two adjacent fixed-point values are + */ static constexpr double PRECISION = 1.0 / PSXFixed::SCALE; - // accuracy is closeness of a value to the "true" value + /** + * @brief The largest difference between a fixed-point value and the + * "true" value it represents. + */ static constexpr double ACCURACY = PSXFixed::PRECISION / 2.0; + /** + * @brief Largest integer value representable by the fixed-point type + */ static constexpr UnderlyingType DECIMAL_MAX = (1 << PSXFixed::DECIMAL_BITS) - 1; + /** + * @brief Smallest integer value representable by the fixed-point type + */ static constexpr UnderlyingType DECIMAL_MIN = -(1 << PSXFixed::DECIMAL_BITS); + /** + * @brief Largest real value representable by the fixed-point type + */ static constexpr double FRACTIONAL_MAX = PSXFixed::DECIMAL_MAX + (1.0 - PSXFixed::PRECISION); + /** + * @brief Smallest real value representable by the fixed-point type + */ static constexpr double FRACTIONAL_MIN = PSXFixed::DECIMAL_MIN; - + /** + * @brief Largest PSXFixed value + */ static constexpr PSXFixed MAX() { return PSXFixed((UnderlyingType)2147483647); } - + /** + * @brief Smallest PSXFixed value + */ static constexpr PSXFixed MIN() { return PSXFixed((UnderlyingType)-2147483648); } - /** * @brief Default constructor, creates a PSXFixed instance with value `0.0_fx` */ @@ -194,6 +233,9 @@ namespace com::saxbophone::unmoving { * @note Although conforming C-libraries check if `buffer == nullptr` for you, the implementation of `vsnprintf()` * in libPSn00bSDK, which this project is intended for use with, doesn't seem to check if `buffer == NULL`, hence * the need to check it here. + * @todo Consider replacing the call to `snprintf()` with a call to + * `sprintf()` --it looks like the original Sony C library doesn't support + * `snprintf()`... */ constexpr bool to_c_str(char* buffer, size_t buffer_size) const { // don't write to a null-pointer! From 2270bf6b049c5b985a7ceca6f46285553fd5a85e Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 07:22:45 +0100 Subject: [PATCH 06/18] Added a bunch more content to README in preparation for public release --- README.md | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f1d957f..492a92a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,40 @@ # Unmoving -More convenient fixed-point arithmetic for the Sony PlayStation -- [unmoving](@ref com::saxbophone::unmoving) API reference +Unmoving is a C++ header-only library providing more convenient +fixed-point arithmetic for the Sony PlayStation ("PS1"), in the form of a +C++ class that wraps the native integer type used by the console standard +library for performing fixed-point calculations. This class is intended to +remove much of the more tedious aspects of the boilerplate code required to +handle numbers in this way. The author hopes that it is useful. + +## Getting it + +Unmoving is written in C++20 and can target the PlayStation or most desktop OSes. +In all cases, you will need a recent C++ compiler in order to build C++20 code. + +_TODO: Instructions go here for using Unmoving with PSn00bSDK_ + +_TODO: Instructions go here for retrieving the library with CMake or just grabbing the header_ + +### Some general notes for running on the PlayStation + +- Although written in C++20, Unmoving does not rely upon the C++ standard library or STL. The only dependencies it has are satisfied by the minimal C standard library that comes with PSn00bSDK. +- Unmoving has been tested and confirmed to run on PCSXR, the PlayStation emulator. There is no reason why it wouldn't also run on real PlayStation hardware, but this has not yet been tested. +- Unmoving hasn't been profiled for performance on the PlayStation. Vague observations from testing with PCSXR suggest its efficiency is reasonable, maybe even decent, but this area needs further investigation —particularly for the multiplication and division routines. + +## Test suite + +Unmoving has a thorough unit test suite, however this cannot be built for the PlayStation due the extensive C++ library dependencies of the test suite itself. This test suite is run in CI for Linux, macOS and Windows. You can run the tests yourself by building the project in Debug mode or with `ENABLE_TESTS=ON` with CMake: + +```sh +git checkout git@github.com:saxbophone/unmoving.git +cd unmoving/build +# debug mode is the default +cmake .. +# OR alternatively (builds tests but in optimised Release mode) +cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON +# runs the tests with 5 threads +ctest -j 5 +``` + +- [API reference](@ref com::saxbophone::unmoving) From 83bae9d0927a5c263f6012b25f8874cfdf6a16e3 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 07:59:41 +0100 Subject: [PATCH 07/18] Added placehold usage section --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 492a92a..4abf0e7 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,12 @@ _TODO: Instructions go here for retrieving the library with CMake or just grabbi - Unmoving has been tested and confirmed to run on PCSXR, the PlayStation emulator. There is no reason why it wouldn't also run on real PlayStation hardware, but this has not yet been tested. - Unmoving hasn't been profiled for performance on the PlayStation. Vague observations from testing with PCSXR suggest its efficiency is reasonable, maybe even decent, but this area needs further investigation —particularly for the multiplication and division routines. +## Usage + +_TODO: Code samples_ + +Further reading: [API reference](https://saxbophone.com/unmoving/) + ## Test suite Unmoving has a thorough unit test suite, however this cannot be built for the PlayStation due the extensive C++ library dependencies of the test suite itself. This test suite is run in CI for Linux, macOS and Windows. You can run the tests yourself by building the project in Debug mode or with `ENABLE_TESTS=ON` with CMake: @@ -36,5 +42,3 @@ cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON # runs the tests with 5 threads ctest -j 5 ``` - -- [API reference](@ref com::saxbophone::unmoving) From 5c7ec3e268d14c54afb43493948bc4f046662d95 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 08:19:26 +0100 Subject: [PATCH 08/18] Flatten namespace to "unmoving", added todo item for to_c_str() --- tests/addition.cpp | 2 +- tests/casting.cpp | 2 +- tests/comparisons.cpp | 2 +- tests/constructors.cpp | 2 +- tests/conversion_to_string.cpp | 2 +- tests/conversion_to_string_null.cpp | 2 +- tests/division.cpp | 2 +- tests/equivalences.cpp | 2 +- tests/multiplication.cpp | 2 +- tests/static_checks.cpp | 2 +- tests/subtraction.cpp | 2 +- tests/unary_operations.cpp | 2 +- tests/user_defined_literals.cpp | 2 +- unmoving/include/unmoving/PSXFixed.hpp | 4 +++- 14 files changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/addition.cpp b/tests/addition.cpp index e13b972..c98fdfe 100644 --- a/tests/addition.cpp +++ b/tests/addition.cpp @@ -20,7 +20,7 @@ #include "config.hpp" -using namespace com::saxbophone::unmoving; +using namespace unmoving; using Underlying = PSXFixed::UnderlyingType; // calculated propagated accuracy error after an addition diff --git a/tests/casting.cpp b/tests/casting.cpp index 74c308f..1b30f47 100644 --- a/tests/casting.cpp +++ b/tests/casting.cpp @@ -17,7 +17,7 @@ #include "config.hpp" -using namespace com::saxbophone::unmoving; +using namespace unmoving; using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Casting") { diff --git a/tests/comparisons.cpp b/tests/comparisons.cpp index d2d5e1a..c20770a 100644 --- a/tests/comparisons.cpp +++ b/tests/comparisons.cpp @@ -15,7 +15,7 @@ #include "config.hpp" -using namespace com::saxbophone::unmoving; +using namespace unmoving; using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Comparisons") { diff --git a/tests/constructors.cpp b/tests/constructors.cpp index 36fd78d..fd15f2e 100644 --- a/tests/constructors.cpp +++ b/tests/constructors.cpp @@ -19,7 +19,7 @@ #include "config.hpp" -using namespace com::saxbophone::unmoving; +using namespace unmoving; using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Constructors") { diff --git a/tests/conversion_to_string.cpp b/tests/conversion_to_string.cpp index e5c7595..77f065a 100644 --- a/tests/conversion_to_string.cpp +++ b/tests/conversion_to_string.cpp @@ -19,7 +19,7 @@ #include "config.hpp" -using namespace com::saxbophone::unmoving; +using namespace unmoving; TEST_CASE("Conversion to String") { SECTION("PSXFixed.to_c_str() creates a C string with the value's decimal respresentation") { diff --git a/tests/conversion_to_string_null.cpp b/tests/conversion_to_string_null.cpp index 3508679..dd11759 100644 --- a/tests/conversion_to_string_null.cpp +++ b/tests/conversion_to_string_null.cpp @@ -13,7 +13,7 @@ #include -using namespace com::saxbophone::unmoving; +using namespace unmoving; TEST_CASE("PSXFixed.to_c_str() returns false when buffer is a null pointer") { PSXFixed var; diff --git a/tests/division.cpp b/tests/division.cpp index c01f953..a2bd59d 100644 --- a/tests/division.cpp +++ b/tests/division.cpp @@ -15,7 +15,7 @@ #include "config.hpp" -using namespace com::saxbophone::unmoving; +using namespace unmoving; using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Division") { diff --git a/tests/equivalences.cpp b/tests/equivalences.cpp index 347539f..ee63375 100644 --- a/tests/equivalences.cpp +++ b/tests/equivalences.cpp @@ -17,7 +17,7 @@ #include "config.hpp" -using namespace com::saxbophone::unmoving; +using namespace unmoving; using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Equivalences") { diff --git a/tests/multiplication.cpp b/tests/multiplication.cpp index a1bf662..054b386 100644 --- a/tests/multiplication.cpp +++ b/tests/multiplication.cpp @@ -17,7 +17,7 @@ #include "config.hpp" -using namespace com::saxbophone::unmoving; +using namespace unmoving; using Underlying = PSXFixed::UnderlyingType; template diff --git a/tests/static_checks.cpp b/tests/static_checks.cpp index 4d624d8..ff15856 100644 --- a/tests/static_checks.cpp +++ b/tests/static_checks.cpp @@ -23,7 +23,7 @@ // various static (compile-time) checks on properties of PSXFixed class -using namespace com::saxbophone::unmoving; +using namespace unmoving; using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Static Checks") { diff --git a/tests/subtraction.cpp b/tests/subtraction.cpp index 05344dd..5c44061 100644 --- a/tests/subtraction.cpp +++ b/tests/subtraction.cpp @@ -20,7 +20,7 @@ #include "config.hpp" -using namespace com::saxbophone::unmoving; +using namespace unmoving; using Underlying = PSXFixed::UnderlyingType; // calculated propagated accuracy error after a subtraction diff --git a/tests/unary_operations.cpp b/tests/unary_operations.cpp index a616fbf..3c35d4c 100644 --- a/tests/unary_operations.cpp +++ b/tests/unary_operations.cpp @@ -15,7 +15,7 @@ #include "config.hpp" -using namespace com::saxbophone::unmoving; +using namespace unmoving; using Underlying = PSXFixed::UnderlyingType; TEST_CASE("Unary operations") { diff --git a/tests/user_defined_literals.cpp b/tests/user_defined_literals.cpp index 96e27b6..dfa34d9 100644 --- a/tests/user_defined_literals.cpp +++ b/tests/user_defined_literals.cpp @@ -15,7 +15,7 @@ #include "config.hpp" -using namespace com::saxbophone::unmoving; +using namespace unmoving; /* * NOTE: we shouldn't test any negative literals here, because this would be diff --git a/unmoving/include/unmoving/PSXFixed.hpp b/unmoving/include/unmoving/PSXFixed.hpp index 0d25035..85b8d81 100644 --- a/unmoving/include/unmoving/PSXFixed.hpp +++ b/unmoving/include/unmoving/PSXFixed.hpp @@ -41,7 +41,7 @@ #include // snprintf #include // abs -namespace com::saxbophone::unmoving { +namespace unmoving { class PSXFixed; // forward-declaration to allow declaration of user-defined literals /** @@ -226,6 +226,7 @@ namespace com::saxbophone::unmoving { } /** * @brief Stringifies the PSXFixed-point value to a C-string + * @details Output is equivalent to `printf()`-family `%.6f`, so trailing zeroes are always displayed * @param buffer pointer to array of `char`. Must be non-null and pointing to buffer of size `buffer_size`. * @param[out] buffer_size size of `buffer`. Should be at least `15`. * @returns `false` if buffer could not be written, because buffer_size wasn't big enough @@ -236,6 +237,7 @@ namespace com::saxbophone::unmoving { * @todo Consider replacing the call to `snprintf()` with a call to * `sprintf()` --it looks like the original Sony C library doesn't support * `snprintf()`... + * @todo Consider adding the ability to reduce the number of displayed decimal places, or to remove trailing zeroes */ constexpr bool to_c_str(char* buffer, size_t buffer_size) const { // don't write to a null-pointer! From d7351046a1df1ca766cfe5eafcb58757d8083e89 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 08:20:42 +0100 Subject: [PATCH 09/18] Remove unused CPP file and set project version number --- CMakeLists.txt | 2 +- main.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fc65d0..b8f5029 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ else() set(UNMOVING_SUBPROJECT ON) endif() -project(Unmoving VERSION 0.0.0 LANGUAGES CXX) +project(Unmoving VERSION 0.1.0 LANGUAGES CXX) find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 237c8ce..0000000 --- a/main.cpp +++ /dev/null @@ -1 +0,0 @@ -int main() {} From 7d4b5c1893b7ac613d562518f7d0dae9e00961d0 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 09:42:37 +0100 Subject: [PATCH 10/18] Added sample usage program to README It's not quite complete yet but a good primer --- README.md | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4abf0e7..b076d1c 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,68 @@ _TODO: Instructions go here for retrieving the library with CMake or just grabbi ## Usage -_TODO: Code samples_ +```cpp +#include +#include + +#include + + +using namespace unmoving; + +void print(const PSXFixed& fixed); + +int main() { + PSXFixed d; // default-initialised + print(d); // -> "0.000000" + // uses custom user-defined-literal, equivalent to the previous statement + PSXFixed z = 0.0_fx, v = 0_fx; + print(z); // -> "0.000000" + print(v); // -> "0.000000" + + // contrasting use of custom literals vs built-in literals: + PSXFixed c = 123456_fx; + print(c); // -> "123456.000000" + PSXFixed b = 123456; // -> equivalent to reinterpret_cast<>() + // i.e. takes 123456 to be the raw integer + // representation of a fixed-point value + print(b); // -> "30.140625" + // NOTE: c and b have different values! + assert(b != c); + // use PSXFixed::from_integer() to value-convert from integer + PSXFixed i = PSXFixed::from_integer(123456); // -> 123456.0_fx + print(i); // -> "123456.000000" + assert(i == c); + + // arithmetic expressions using fixed-point type + // note that as all methods are constexpr, constants can be folded at compile-time + static constexpr PSXFixed compile_time_expression = (3.14159265_fx / 3) + 0.02_fx * 45; + /* + * An optimising compiler can put the variable declared above in rodata as a constant: + * + * Disassembly of section .rodata: + * + * ...[truncated]... + * + * 0000000000400ca4 : + * 400ca4: 2b 1f sub (%rdi),%ebx + * ... + * + * NOTE here that 0x1F2B as seen in the assembly is the decimal value 7979 + * which is the raw fixed-point value for 1.947998 + */ + print(compile_time_expression); // -> "1.947998" + // fixed-point instances cast to int implicitly, yielding their raw value: + std::cout << compile_time_expression << std::endl; // -> "7979" +} + +void print(const PSXFixed& fixed) { + char buffer[15] = {}; + if (fixed.to_c_str(buffer, sizeof(buffer))) { + std::cout << buffer << std::endl; + } +} +``` Further reading: [API reference](https://saxbophone.com/unmoving/) @@ -39,6 +100,10 @@ cd unmoving/build cmake .. # OR alternatively (builds tests but in optimised Release mode) cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON + +# compile tests, using 5 threads +cmake --build . -j 5 + # runs the tests with 5 threads ctest -j 5 ``` From eefda96849dd0ce380c315629cdc383f997cc765 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 10:07:39 +0100 Subject: [PATCH 11/18] Added more sections to README: - further usage instructions - limitations - acknowledgements - brief software license explainer --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index b076d1c..818976d 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,18 @@ _TODO: Instructions go here for using Unmoving with PSn00bSDK_ _TODO: Instructions go here for retrieving the library with CMake or just grabbing the header_ +> This project is licensed under the Mozilla Public License v2.0. +> +> This is a permissive copyleft software license which applies the copyleft +> provisions to this project's source code only. This means you can use it in any +> project, whether open-source or not, without needing to disclose _your_ source. +> However, if you make modifications to _this_ project which you include in a +> project that you distribute (even a closed-source one), you are required to share +> the modifications you made to this project, but these parts only. +> +> Basically, if you modify _Unmoving_ and distribute it, you need to publish your +> modifications. + ### Some general notes for running on the PlayStation - Although written in C++20, Unmoving does not rely upon the C++ standard library or STL. The only dependencies it has are satisfied by the minimal C standard library that comes with PSn00bSDK. @@ -87,6 +99,18 @@ void print(const PSXFixed& fixed) { } ``` +Because `PSXFixed` objects implicitly cast to their base integer type, it is +possible to use them more or less as a drop-in replacement for "raw" integers +for fixed-point maths, including being able to pass them into and out of the +PSX standard library functions such as `rcos()` and friends. + +The only thing one has to be careful about is avoiding implicit integer conversions +when the intention is to convert by _value_ rather than raw bit-pattern, as +demonstrated in the sample code above. +[PSXFixed::from_integer()](@ref unmoving::PSXFixed::from_integer()) and +[PSXFixed::to_integer()](@ref unmoving::PSXFixed::to_integer()) are provided for such +value-conversions. + Further reading: [API reference](https://saxbophone.com/unmoving/) ## Test suite @@ -107,3 +131,24 @@ cmake --build . -j 5 # runs the tests with 5 threads ctest -j 5 ``` + +## Limitations + +The author of this software was very new to PlayStation programming at the time +he wrote it, although having decent knowledge of C and C++. As such, there are +no doubt going to be some oversights made on his part about the intricacies of +PSX programming that haven't been considered in the project's design or +implementation. + +If you feel something is missing or can be improved, I would be very grateful +for your input and invite you to contribute issues or pull requests at this +project's page on Github: [https://github.com/saxbophone/unmoving](https://github.com/saxbophone/unmoving). + +## Acknowledgements + +Big thanks to [Lameguy64](https://github.com/lameguy64) for both his +[series of tutorials](http://lameguy64.net/tutorials/pstutorials/) on PlayStation +programming (the fixed-point arithmetic section of which was particularly +helpful in the making of this software) and for his open-source PSX SDK +[PSn00bSDK](https://github.com/Lameguy64/PSn00bSDK), which this project is tested +with and which I thoroughly recommend checking out. Your work inspires me, sir! From 52b74864ea86ab00a3682340e2fdd58c5b36f30b Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 10:29:44 +0100 Subject: [PATCH 12/18] Added notes about toolchain setup, cmake usage and bad joke at end --- README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 818976d..f900d68 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,51 @@ handle numbers in this way. The author hopes that it is useful. Unmoving is written in C++20 and can target the PlayStation or most desktop OSes. In all cases, you will need a recent C++ compiler in order to build C++20 code. -_TODO: Instructions go here for using Unmoving with PSn00bSDK_ +For getting a toolchain that can target the PlayStation and which can compile +C++20 code, you will need to compile a toolchain yourself. I recommend following +the instructions in PSn00bSDK (which this project is tested with) for manually +compiling toolchains +([https://github.com/Lameguy64/PSn00bSDK/blob/ffa679d4d24b891cb59aba10946368f2ec00c391/toolchain.txt](https://github.com/Lameguy64/PSn00bSDK/blob/ffa679d4d24b891cb59aba10946368f2ec00c391/toolchain.txt)), **but choose newer versions of Binutils and GCC than are specified**. -_TODO: Instructions go here for retrieving the library with CMake or just grabbing the header_ +I used **Binutils 2.37** and **GCC 10.3.0**. + +Of course, as this is a header-only library, you could just head over to the +[releases page](https://github.com/saxbophone/unmoving/releases) on Github and +download the latest version of it from there and then put it in your include path to use it in your projects. + +### CMake integration + +Alternatively, you can fetch the project with CMake if you like. You need CMake 3.15 or newer +to do this. + +A convenient way to do this is to use CPM +([https://github.com/cpm-cmake/CPM.cmake](https://github.com/cpm-cmake/CPM.cmake)) +to fetch the project from Github for you: + +```cmake +CPMFindPackage( + NAME Unmoving + GIT_REPOSITORY git@github.com:saxbophone/unmoving.git + GIT_TAG v0.1.0 +) +``` + +Or if you don't want to use a third-party CMake tool, CMake's `FetchContent()` +API can be used in a similar way instead. + +You could also clone this project's source code, build and install it with CMake +and then use CMake's `find_package()` to use it in your project. `CPMFindPackage()` +will also use locally-installed packages if you install it this way. + +You can then link your build targets to _Unmoving_ in the typical way: + +```cmake +# sample target "main" +add_executable(main main.cpp) +target_link_libraries(main Unmoving::unmoving) +``` + +### License > This project is licensed under the Mozilla Public License v2.0. > @@ -152,3 +194,9 @@ programming (the fixed-point arithmetic section of which was particularly helpful in the making of this software) and for his open-source PSX SDK [PSn00bSDK](https://github.com/Lameguy64/PSn00bSDK), which this project is tested with and which I thoroughly recommend checking out. Your work inspires me, sir! + +> "What do you call a decimal point which sticks around in the same place?" +> +> ... +> +> _UNMOVING!_ From d798dc4a77d0f28bbdb102623fa6b110c8876e0a Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 10:44:34 +0100 Subject: [PATCH 13/18] Replace build with just copying header file --- .github/workflows/build-release.yml | 52 +++-------------------------- 1 file changed, 5 insertions(+), 47 deletions(-) diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 614259c..b804d41 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -5,58 +5,16 @@ on: types: [published] jobs: + # just upload the header file to the Github release object for the "build" job build-release: - runs-on: ${{ matrix.os }} - env: - BUILD_TYPE: Release - strategy: - fail-fast: false - matrix: - # specify a specific compiler to build with each OS separately - include: - - platform_name: linux - os: ubuntu-20.04 - cxx: g++-10 - - platform_name: macos - os: macos-10.15 - cxx: clang++ - # NOTE: CXX seems to be ignored on Windows, but specify it anyway for consistency - - platform_name: windows - os: windows-2019 - cxx: msvc - + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - - name: Configure CMake - env: - CXX: ${{ matrix.cxx }} - # Use a bash shell so we can use the same syntax for environment variable - # access regardless of the host operating system - shell: bash - working-directory: ${{github.workspace}}/build - # Note the current convention is to use the -S and -B options here to specify source - # and build directories, but this is only available with CMake 3.13 and higher. - # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX:PATH=$GITHUB_WORKSPACE/artifacts - - - name: Build - working-directory: ${{github.workspace}}/build - shell: bash - # Execute the build. You can specify a specific target with "--target " - run: cmake --build . --config $BUILD_TYPE - - - name: Install - working-directory: ${{github.workspace}}/build - shell: bash - # Use CMake to "install" build artifacts (only interested in CMake registered targets) to our custom artifacts directory - run: cmake --install . --config $BUILD_TYPE - - - name: Upload + - name: Upload Header file uses: actions/upload-artifact@v2 with: - name: unmoving_build_${{ github.run_number }}_${{ matrix.platform_name }} - path: ${{github.workspace}}/artifacts + name: PSXFixed.hpp + path: ${{github.workspace}}/unmoving/include/PSXFixed.hpp build-docs: runs-on: ubuntu-20.04 # don't deploy docs unless release build succeeds From 7f7e4a99200671421db4bc791d9e35807d407306 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 10:53:46 +0100 Subject: [PATCH 14/18] Updated build-release workflow: - consolidated the "build" and docs build into one job - version-stamp the header file before adding it as a release artifact --- .github/workflows/build-release.yml | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index b804d41..6240674 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -5,34 +5,30 @@ on: types: [published] jobs: - # just upload the header file to the Github release object for the "build" job - build-release: + build: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 + - name: Set Tag Name + # trim prefix from ref to get tag name + run: echo "TAG_NAME=${GITHUB_REF#'refs/tags/'}" >> $GITHUB_ENV + - name: Version-stamp Header file + working-directory: ${{github.workspace}} + run: | + echo "// Unmoving $TAG_NAME downloaded from Github at https://github.com/saxbophone/unmoving/releases" > header_stub.hpp + cat header_stub.hpp unmoving/include/unmoving/PSXFixed.hpp > PSXFixed.hpp - name: Upload Header file uses: actions/upload-artifact@v2 with: name: PSXFixed.hpp - path: ${{github.workspace}}/unmoving/include/PSXFixed.hpp - build-docs: - runs-on: ubuntu-20.04 - # don't deploy docs unless release build succeeds - needs: build-release - steps: - - uses: actions/checkout@v2 - - name: Set Tag Name - shell: bash - # trim prefix from ref to get tag name - run: echo "TAG_NAME=${GITHUB_REF#'refs/tags/'}" >> $GITHUB_ENV + working-directory: ${{github.workspace}} + path: PSXFixed.hpp - name: Format Docs Version Name - shell: bash # trim patch version off version number as minor version specifies ABI changes run: echo "DOCS_VERSION=${TAG_NAME%.*}" >> $GITHUB_ENV - name: Build Doxygen Docs uses: mattnotmitt/doxygen-action@v1.3.3 - name: Set up latest docs auto-linking - shell: bash working-directory: ${{github.workspace}} # make docs folder, move docs there, call script to generate HTML redirect in index run: | From 628119ec37de122f8e55ffc3a9e8c2b24f5d7a03 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 11:12:00 +0100 Subject: [PATCH 15/18] Modified build-release github workflow to upload header for me --- .github/workflows/build-release.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 6240674..96c0300 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -13,23 +13,29 @@ jobs: # trim prefix from ref to get tag name run: echo "TAG_NAME=${GITHUB_REF#'refs/tags/'}" >> $GITHUB_ENV - name: Version-stamp Header file - working-directory: ${{github.workspace}} run: | echo "// Unmoving $TAG_NAME downloaded from Github at https://github.com/saxbophone/unmoving/releases" > header_stub.hpp cat header_stub.hpp unmoving/include/unmoving/PSXFixed.hpp > PSXFixed.hpp + - name: Get release + id: get_release + uses: bruceadams/get-release@v1.2.3 + env: + GITHUB_TOKEN: ${{ github.token }} - name: Upload Header file - uses: actions/upload-artifact@v2 + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ github.token }} with: - name: PSXFixed.hpp - working-directory: ${{github.workspace}} - path: PSXFixed.hpp + upload_url: ${{ steps.get_release.outputs.upload_url }} + asset_path: ./PSXFixed.hpp + asset_name: PSXFixed.hpp + asset_content_type: text/plain - name: Format Docs Version Name # trim patch version off version number as minor version specifies ABI changes run: echo "DOCS_VERSION=${TAG_NAME%.*}" >> $GITHUB_ENV - name: Build Doxygen Docs uses: mattnotmitt/doxygen-action@v1.3.3 - name: Set up latest docs auto-linking - working-directory: ${{github.workspace}} # make docs folder, move docs there, call script to generate HTML redirect in index run: | mkdir docs From 3e89bacf961d1c5c73b907d453a74c64e29674d3 Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 11:12:53 +0100 Subject: [PATCH 16/18] Version bump for release-build test --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8f5029..88dfe81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ else() set(UNMOVING_SUBPROJECT ON) endif() -project(Unmoving VERSION 0.1.0 LANGUAGES CXX) +project(Unmoving VERSION 0.0.1 LANGUAGES CXX) find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) From 18b655ad3d47e5d1299c61e12b577e343a8f82eb Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 11:18:01 +0100 Subject: [PATCH 17/18] Initial build-release test successful. Let's include the release's exact URL too --- .github/workflows/build-release.yml | 10 ++++++---- CMakeLists.txt | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 96c0300..0fb2503 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -12,15 +12,17 @@ jobs: - name: Set Tag Name # trim prefix from ref to get tag name run: echo "TAG_NAME=${GITHUB_REF#'refs/tags/'}" >> $GITHUB_ENV - - name: Version-stamp Header file - run: | - echo "// Unmoving $TAG_NAME downloaded from Github at https://github.com/saxbophone/unmoving/releases" > header_stub.hpp - cat header_stub.hpp unmoving/include/unmoving/PSXFixed.hpp > PSXFixed.hpp - name: Get release id: get_release uses: bruceadams/get-release@v1.2.3 env: GITHUB_TOKEN: ${{ github.token }} + - name: Version-stamp Header file + env: + RELEASE_URL: ${{ steps.get_release.outputs.html_url }} + run: | + echo "// Unmoving $TAG_NAME downloaded from Github at $RELEASE_URL" > header_stub.hpp + cat header_stub.hpp unmoving/include/unmoving/PSXFixed.hpp > PSXFixed.hpp - name: Upload Header file uses: actions/upload-release-asset@v1.0.2 env: diff --git a/CMakeLists.txt b/CMakeLists.txt index 88dfe81..4aea178 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ else() set(UNMOVING_SUBPROJECT ON) endif() -project(Unmoving VERSION 0.0.1 LANGUAGES CXX) +project(Unmoving VERSION 0.0.2 LANGUAGES CXX) find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) From b89cc982e9e2223b8cfac0b8364ce12eddc992bf Mon Sep 17 00:00:00 2001 From: Joshua Saxby Date: Wed, 22 Sep 2021 11:25:28 +0100 Subject: [PATCH 18/18] v0.1.0 release --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4aea178..b8f5029 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ else() set(UNMOVING_SUBPROJECT ON) endif() -project(Unmoving VERSION 0.0.2 LANGUAGES CXX) +project(Unmoving VERSION 0.1.0 LANGUAGES CXX) find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM)