From 1b4b6b0aee6d4ea338c4755a5f6dcd6b73e280ee Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Jan 2020 23:14:35 -0500 Subject: [PATCH 1/3] Renames: NumberTheory -> Numeric. --- Analyser/Static/Acorn/Disk.cpp | 2 +- Analyser/Static/Acorn/Tape.cpp | 2 +- {NumberTheory => Numeric}/CRC.hpp | 0 {NumberTheory => Numeric}/Factors.hpp | 22 ++------------ {NumberTheory => Numeric}/LFSR.hpp | 7 +++-- .../Clock Signal.xcodeproj/project.pbxproj | 29 ++++++++++--------- Storage/Disk/Controller/DiskController.cpp | 2 +- Storage/Disk/Controller/MFMDiskController.hpp | 2 +- Storage/Disk/DiskImage/Formats/WOZ.hpp | 2 +- Storage/Disk/Encodings/MFM/Encoder.cpp | 2 +- Storage/Disk/Encodings/MFM/Encoder.hpp | 2 +- Storage/Disk/Encodings/MFM/Shifter.hpp | 2 +- Storage/Disk/Track/PCMSegment.hpp | 4 +-- Storage/Disk/Track/PCMTrack.cpp | 2 +- Storage/Storage.hpp | 6 ++-- Storage/Tape/Parsers/Acorn.hpp | 2 +- Storage/Tape/Tape.cpp | 2 +- Storage/TimedEventLoop.cpp | 2 +- 18 files changed, 39 insertions(+), 53 deletions(-) rename {NumberTheory => Numeric}/CRC.hpp (100%) rename {NumberTheory => Numeric}/Factors.hpp (64%) rename {NumberTheory => Numeric}/LFSR.hpp (95%) diff --git a/Analyser/Static/Acorn/Disk.cpp b/Analyser/Static/Acorn/Disk.cpp index ff4327b91..42d0b2065 100644 --- a/Analyser/Static/Acorn/Disk.cpp +++ b/Analyser/Static/Acorn/Disk.cpp @@ -10,7 +10,7 @@ #include "../../../Storage/Disk/Controller/DiskController.hpp" #include "../../../Storage/Disk/Encodings/MFM/Parser.hpp" -#include "../../../NumberTheory/CRC.hpp" +#include "../../../Numeric/CRC.hpp" #include diff --git a/Analyser/Static/Acorn/Tape.cpp b/Analyser/Static/Acorn/Tape.cpp index 43f71e69e..2a5000612 100644 --- a/Analyser/Static/Acorn/Tape.cpp +++ b/Analyser/Static/Acorn/Tape.cpp @@ -10,7 +10,7 @@ #include -#include "../../../NumberTheory/CRC.hpp" +#include "../../../Numeric/CRC.hpp" #include "../../../Storage/Tape/Parsers/Acorn.hpp" using namespace Analyser::Static::Acorn; diff --git a/NumberTheory/CRC.hpp b/Numeric/CRC.hpp similarity index 100% rename from NumberTheory/CRC.hpp rename to Numeric/CRC.hpp diff --git a/NumberTheory/Factors.hpp b/Numeric/Factors.hpp similarity index 64% rename from NumberTheory/Factors.hpp rename to Numeric/Factors.hpp index 36321fdd0..639abdae5 100644 --- a/NumberTheory/Factors.hpp +++ b/Numeric/Factors.hpp @@ -12,27 +12,12 @@ #include #include -namespace NumberTheory { +namespace Numeric { /*! @returns The greatest common divisor of @c a and @c b. */ template T greatest_common_divisor(T a, T b) { -#if __cplusplus > 201402L return std::gcd(a, b); -#else - if(a < b) { - std::swap(a, b); - } - - while(1) { - if(!a) return b; - if(!b) return a; - - T remainder = a%b; - a = b; - b = remainder; - } -#endif } /*! @@ -40,10 +25,7 @@ namespace NumberTheory { common divisor. */ template T least_common_multiple(T a, T b) { - if(a == b) return a; - - T gcd = greatest_common_divisor(a, b); - return (a / gcd) * (b / gcd) * gcd; + return std::lcm(a, b); } } diff --git a/NumberTheory/LFSR.hpp b/Numeric/LFSR.hpp similarity index 95% rename from NumberTheory/LFSR.hpp rename to Numeric/LFSR.hpp index 9848b8121..9802bb893 100644 --- a/NumberTheory/LFSR.hpp +++ b/Numeric/LFSR.hpp @@ -9,8 +9,9 @@ #ifndef LFSR_h #define LFSR_h -template struct LSFRPolynomial { -}; +namespace Numeric { + +template struct LSFRPolynomial {}; // The following were taken 'at random' from https://users.ece.cmu.edu/~koopman/lfsr/index.html template <> struct LSFRPolynomial { @@ -61,4 +62,6 @@ template diff --git a/Storage/Disk/Encodings/MFM/Encoder.cpp b/Storage/Disk/Encodings/MFM/Encoder.cpp index aba0812e1..4bdc1b7a8 100644 --- a/Storage/Disk/Encodings/MFM/Encoder.cpp +++ b/Storage/Disk/Encodings/MFM/Encoder.cpp @@ -10,7 +10,7 @@ #include "Constants.hpp" #include "../../Track/PCMTrack.hpp" -#include "../../../../NumberTheory/CRC.hpp" +#include "../../../../Numeric/CRC.hpp" #include #include diff --git a/Storage/Disk/Encodings/MFM/Encoder.hpp b/Storage/Disk/Encodings/MFM/Encoder.hpp index 443846268..822ee4d89 100644 --- a/Storage/Disk/Encodings/MFM/Encoder.hpp +++ b/Storage/Disk/Encodings/MFM/Encoder.hpp @@ -15,7 +15,7 @@ #include "Sector.hpp" #include "../../Track/Track.hpp" -#include "../../../../NumberTheory/CRC.hpp" +#include "../../../../Numeric/CRC.hpp" namespace Storage { namespace Encodings { diff --git a/Storage/Disk/Encodings/MFM/Shifter.hpp b/Storage/Disk/Encodings/MFM/Shifter.hpp index 35234c1ca..f55b8d417 100644 --- a/Storage/Disk/Encodings/MFM/Shifter.hpp +++ b/Storage/Disk/Encodings/MFM/Shifter.hpp @@ -11,7 +11,7 @@ #include #include -#include "../../../../NumberTheory/CRC.hpp" +#include "../../../../Numeric/CRC.hpp" namespace Storage { namespace Encodings { diff --git a/Storage/Disk/Track/PCMSegment.hpp b/Storage/Disk/Track/PCMSegment.hpp index 801caada4..c5a86b9c8 100644 --- a/Storage/Disk/Track/PCMSegment.hpp +++ b/Storage/Disk/Track/PCMSegment.hpp @@ -14,7 +14,7 @@ #include #include "../../Storage.hpp" -#include "../../../NumberTheory/LFSR.hpp" +#include "../../../Numeric/LFSR.hpp" #include "Track.hpp" namespace Storage { @@ -200,7 +200,7 @@ class PCMSegmentEventSource { std::shared_ptr segment_; std::size_t bit_pointer_; Track::Event next_event_; - LFSR lfsr_; + Numeric::LFSR lfsr_; }; } diff --git a/Storage/Disk/Track/PCMTrack.cpp b/Storage/Disk/Track/PCMTrack.cpp index 85da85c47..695a66716 100644 --- a/Storage/Disk/Track/PCMTrack.cpp +++ b/Storage/Disk/Track/PCMTrack.cpp @@ -7,7 +7,7 @@ // #include "PCMTrack.hpp" -#include "../../../NumberTheory/Factors.hpp" +#include "../../../Numeric/Factors.hpp" #include "../../../Outputs/Log.hpp" using namespace Storage::Disk; diff --git a/Storage/Storage.hpp b/Storage/Storage.hpp index 01f7129a8..4a1aeb13a 100644 --- a/Storage/Storage.hpp +++ b/Storage/Storage.hpp @@ -9,7 +9,7 @@ #ifndef Storage_hpp #define Storage_hpp -#include "../NumberTheory/Factors.hpp" +#include "../Numeric/Factors.hpp" #include #include #include @@ -39,7 +39,7 @@ struct Time { and @c clock_rate. */ void simplify() { - unsigned int common_divisor = NumberTheory::greatest_common_divisor(length, clock_rate); + unsigned int common_divisor = Numeric::greatest_common_divisor(length, clock_rate); length /= common_divisor; clock_rate /= common_divisor; } @@ -229,7 +229,7 @@ struct Time { } if(long_length > std::numeric_limits::max() || long_clock_rate > std::numeric_limits::max()) { - uint64_t common_divisor = NumberTheory::greatest_common_divisor(long_length, long_clock_rate); + uint64_t common_divisor = Numeric::greatest_common_divisor(long_length, long_clock_rate); long_length /= common_divisor; long_clock_rate /= common_divisor; diff --git a/Storage/Tape/Parsers/Acorn.hpp b/Storage/Tape/Parsers/Acorn.hpp index 3dd9c32d3..b3d8255e2 100644 --- a/Storage/Tape/Parsers/Acorn.hpp +++ b/Storage/Tape/Parsers/Acorn.hpp @@ -10,7 +10,7 @@ #define Storage_Tape_Parsers_Acorn_hpp #include "TapeParser.hpp" -#include "../../../NumberTheory/CRC.hpp" +#include "../../../Numeric/CRC.hpp" #include "../../Disk/DPLL/DigitalPhaseLockedLoop.hpp" namespace Storage { diff --git a/Storage/Tape/Tape.cpp b/Storage/Tape/Tape.cpp index a3d8c2f27..105bdfac4 100644 --- a/Storage/Tape/Tape.cpp +++ b/Storage/Tape/Tape.cpp @@ -7,7 +7,7 @@ // #include "Tape.hpp" -#include "../../NumberTheory/Factors.hpp" +#include "../../Numeric/Factors.hpp" using namespace Storage::Tape; diff --git a/Storage/TimedEventLoop.cpp b/Storage/TimedEventLoop.cpp index aba194ae2..90b796288 100644 --- a/Storage/TimedEventLoop.cpp +++ b/Storage/TimedEventLoop.cpp @@ -7,7 +7,7 @@ // #include "TimedEventLoop.hpp" -#include "../NumberTheory/Factors.hpp" +#include "../Numeric/Factors.hpp" #include #include From 98daad45c735d63b942e6e7acfcb2625131935fd Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Jan 2020 23:18:59 -0500 Subject: [PATCH 2/3] Removers Factors.hpp; now this is a C++17 project. --- Numeric/Factors.hpp | 32 ---------------------- Storage/Disk/Controller/DiskController.cpp | 2 -- Storage/Disk/Track/PCMTrack.cpp | 1 - Storage/Storage.hpp | 6 ++-- Storage/Tape/Tape.cpp | 1 - Storage/TimedEventLoop.cpp | 1 - 6 files changed, 3 insertions(+), 40 deletions(-) delete mode 100644 Numeric/Factors.hpp diff --git a/Numeric/Factors.hpp b/Numeric/Factors.hpp deleted file mode 100644 index 639abdae5..000000000 --- a/Numeric/Factors.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// -// Factors.hpp -// Clock Signal -// -// Created by Thomas Harte on 29/07/2016. -// Copyright 2016 Thomas Harte. All rights reserved. -// - -#ifndef Factors_hpp -#define Factors_hpp - -#include -#include - -namespace Numeric { - /*! - @returns The greatest common divisor of @c a and @c b. - */ - template T greatest_common_divisor(T a, T b) { - return std::gcd(a, b); - } - - /*! - @returns The least common multiple of @c a and @c b computed indirectly via the greatest - common divisor. - */ - template T least_common_multiple(T a, T b) { - return std::lcm(a, b); - } -} - -#endif /* Factors_hpp */ diff --git a/Storage/Disk/Controller/DiskController.cpp b/Storage/Disk/Controller/DiskController.cpp index 0cc708748..6afdbc9ce 100644 --- a/Storage/Disk/Controller/DiskController.cpp +++ b/Storage/Disk/Controller/DiskController.cpp @@ -8,8 +8,6 @@ #include "DiskController.hpp" -#include "../../../Numeric/Factors.hpp" - using namespace Storage::Disk; Controller::Controller(Cycles clock_rate) : diff --git a/Storage/Disk/Track/PCMTrack.cpp b/Storage/Disk/Track/PCMTrack.cpp index 695a66716..7fc441f4c 100644 --- a/Storage/Disk/Track/PCMTrack.cpp +++ b/Storage/Disk/Track/PCMTrack.cpp @@ -7,7 +7,6 @@ // #include "PCMTrack.hpp" -#include "../../../Numeric/Factors.hpp" #include "../../../Outputs/Log.hpp" using namespace Storage::Disk; diff --git a/Storage/Storage.hpp b/Storage/Storage.hpp index 4a1aeb13a..92d42ca70 100644 --- a/Storage/Storage.hpp +++ b/Storage/Storage.hpp @@ -9,10 +9,10 @@ #ifndef Storage_hpp #define Storage_hpp -#include "../Numeric/Factors.hpp" #include #include #include +#include namespace Storage { @@ -39,7 +39,7 @@ struct Time { and @c clock_rate. */ void simplify() { - unsigned int common_divisor = Numeric::greatest_common_divisor(length, clock_rate); + unsigned int common_divisor = std::gcd(length, clock_rate); length /= common_divisor; clock_rate /= common_divisor; } @@ -229,7 +229,7 @@ struct Time { } if(long_length > std::numeric_limits::max() || long_clock_rate > std::numeric_limits::max()) { - uint64_t common_divisor = Numeric::greatest_common_divisor(long_length, long_clock_rate); + uint64_t common_divisor = std::gcd(long_length, long_clock_rate); long_length /= common_divisor; long_clock_rate /= common_divisor; diff --git a/Storage/Tape/Tape.cpp b/Storage/Tape/Tape.cpp index 105bdfac4..c14c1b4ce 100644 --- a/Storage/Tape/Tape.cpp +++ b/Storage/Tape/Tape.cpp @@ -7,7 +7,6 @@ // #include "Tape.hpp" -#include "../../Numeric/Factors.hpp" using namespace Storage::Tape; diff --git a/Storage/TimedEventLoop.cpp b/Storage/TimedEventLoop.cpp index 90b796288..2fa932ff9 100644 --- a/Storage/TimedEventLoop.cpp +++ b/Storage/TimedEventLoop.cpp @@ -7,7 +7,6 @@ // #include "TimedEventLoop.hpp" -#include "../Numeric/Factors.hpp" #include #include From add3ebcb44eb3d605eec0ae0332472a899475cb9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 19 Jan 2020 23:23:44 -0500 Subject: [PATCH 3/3] Updates Xcode project. --- OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 13e13a8a6..6fba9e0e8 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -1185,7 +1185,6 @@ 4B7BA03523CEB86000B98D9E /* BD500.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BD500.cpp; path = Oric/BD500.cpp; sourceTree = ""; }; 4B7BA03623CEB86000B98D9E /* BD500.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = BD500.hpp; path = Oric/BD500.hpp; sourceTree = ""; }; 4B7BA03823CEB8D200B98D9E /* DiskController.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = DiskController.hpp; path = Oric/DiskController.hpp; sourceTree = ""; }; - 4B7BA03D23D55E7900B98D9E /* Factors.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Factors.hpp; sourceTree = ""; }; 4B7BA03E23D55E7900B98D9E /* CRC.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CRC.hpp; sourceTree = ""; }; 4B7BA03F23D55E7900B98D9E /* LFSR.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = LFSR.hpp; sourceTree = ""; }; 4B7F188C2154825D00388727 /* MasterSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MasterSystem.cpp; sourceTree = ""; }; @@ -2597,7 +2596,6 @@ 4B7BA03C23D55E7900B98D9E /* Numeric */ = { isa = PBXGroup; children = ( - 4B7BA03D23D55E7900B98D9E /* Factors.hpp */, 4B7BA03E23D55E7900B98D9E /* CRC.hpp */, 4B7BA03F23D55E7900B98D9E /* LFSR.hpp */, );