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 <algorithm> 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 <deque> -#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 <numeric> #include <utility> -namespace NumberTheory { +namespace Numeric { /*! @returns The greatest common divisor of @c a and @c b. */ template<class T> 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<class T> T least_common_multiple(T a, T b) { - if(a == b) return a; - - T gcd = greatest_common_divisor<T>(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 <typename IntType> struct LSFRPolynomial { -}; +namespace Numeric { + +template <typename IntType> struct LSFRPolynomial {}; // The following were taken 'at random' from https://users.ece.cmu.edu/~koopman/lfsr/index.html template <> struct LSFRPolynomial<uint64_t> { @@ -61,4 +62,6 @@ template <typename IntType = uint64_t, IntType polynomial = LSFRPolynomial<IntTy IntType value_ = 0; }; +} + #endif /* LFSR_h */ diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 57685bf15..13e13a8a6 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -1185,7 +1185,9 @@ 4B7BA03523CEB86000B98D9E /* BD500.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BD500.cpp; path = Oric/BD500.cpp; sourceTree = "<group>"; }; 4B7BA03623CEB86000B98D9E /* BD500.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = BD500.hpp; path = Oric/BD500.hpp; sourceTree = "<group>"; }; 4B7BA03823CEB8D200B98D9E /* DiskController.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = DiskController.hpp; path = Oric/DiskController.hpp; sourceTree = "<group>"; }; - 4B7BA03923D5302C00B98D9E /* LFSR.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = LFSR.hpp; path = ../../NumberTheory/LFSR.hpp; sourceTree = "<group>"; }; + 4B7BA03D23D55E7900B98D9E /* Factors.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Factors.hpp; sourceTree = "<group>"; }; + 4B7BA03E23D55E7900B98D9E /* CRC.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CRC.hpp; sourceTree = "<group>"; }; + 4B7BA03F23D55E7900B98D9E /* LFSR.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = LFSR.hpp; sourceTree = "<group>"; }; 4B7F188C2154825D00388727 /* MasterSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MasterSystem.cpp; sourceTree = "<group>"; }; 4B7F188D2154825D00388727 /* MasterSystem.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = MasterSystem.hpp; sourceTree = "<group>"; }; 4B7F1895215486A100388727 /* StaticAnalyser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = StaticAnalyser.hpp; sourceTree = "<group>"; }; @@ -1591,7 +1593,6 @@ 4BB4BFAF22A42F290069048D /* MacintoshIMG.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = MacintoshIMG.hpp; sourceTree = "<group>"; }; 4BB4BFB722A4372E0069048D /* StaticAnalyser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = StaticAnalyser.hpp; sourceTree = "<group>"; }; 4BB4BFB822A4372E0069048D /* StaticAnalyser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StaticAnalyser.cpp; sourceTree = "<group>"; }; - 4BB697C61D4B558F00248BDF /* Factors.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Factors.hpp; path = ../../NumberTheory/Factors.hpp; sourceTree = "<group>"; }; 4BB697C91D4B6D3E00248BDF /* TimedEventLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TimedEventLoop.cpp; sourceTree = "<group>"; }; 4BB697CA1D4B6D3E00248BDF /* TimedEventLoop.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = TimedEventLoop.hpp; sourceTree = "<group>"; }; 4BB697CC1D4BA44400248BDF /* CommodoreGCR.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommodoreGCR.cpp; path = Encodings/CommodoreGCR.cpp; sourceTree = "<group>"; }; @@ -1741,7 +1742,6 @@ 4BF4A2D91F534DB300B171F4 /* TargetPlatforms.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = TargetPlatforms.hpp; sourceTree = "<group>"; }; 4BF52672218E752E00313227 /* ScanTarget.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ScanTarget.hpp; path = ../../Outputs/ScanTarget.hpp; sourceTree = "<group>"; }; 4BF6606A1F281573002CB053 /* ClockReceiver.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ClockReceiver.hpp; sourceTree = "<group>"; }; - 4BF8295F1D8F3C87001BAE39 /* CRC.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = CRC.hpp; path = ../../NumberTheory/CRC.hpp; sourceTree = "<group>"; }; 4BFCA1211ECBDCAF00AC40C1 /* AllRAMProcessor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AllRAMProcessor.cpp; sourceTree = "<group>"; }; 4BFCA1221ECBDCAF00AC40C1 /* AllRAMProcessor.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = AllRAMProcessor.hpp; sourceTree = "<group>"; }; 4BFCA1251ECBE33200AC40C1 /* TestMachineZ80.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestMachineZ80.h; sourceTree = "<group>"; }; @@ -2594,6 +2594,17 @@ path = Coleco; sourceTree = "<group>"; }; + 4B7BA03C23D55E7900B98D9E /* Numeric */ = { + isa = PBXGroup; + children = ( + 4B7BA03D23D55E7900B98D9E /* Factors.hpp */, + 4B7BA03E23D55E7900B98D9E /* CRC.hpp */, + 4B7BA03F23D55E7900B98D9E /* LFSR.hpp */, + ); + name = Numeric; + path = ../../Numeric; + sourceTree = "<group>"; + }; 4B7F188B2154825D00388727 /* MasterSystem */ = { isa = PBXGroup; children = ( @@ -3182,16 +3193,6 @@ path = Macintosh; sourceTree = "<group>"; }; - 4BB697C81D4B559300248BDF /* NumberTheory */ = { - isa = PBXGroup; - children = ( - 4BB697C61D4B558F00248BDF /* Factors.hpp */, - 4BF8295F1D8F3C87001BAE39 /* CRC.hpp */, - 4B7BA03923D5302C00B98D9E /* LFSR.hpp */, - ); - name = NumberTheory; - sourceTree = "<group>"; - }; 4BB697CF1D4BA44900248BDF /* Encodings */ = { isa = PBXGroup; children = ( @@ -3219,7 +3220,7 @@ 4B055A761FAE78210060FFFF /* Frameworks */, 4B86E2581F8C628F006FAA45 /* Inputs */, 4BB73EDC1B587CA500552FC2 /* Machines */, - 4BB697C81D4B559300248BDF /* NumberTheory */, + 4B7BA03C23D55E7900B98D9E /* Numeric */, 4B366DFD1B5C165F0026627B /* Outputs */, 4BB73EDD1B587CA500552FC2 /* Processors */, 4BB73E9F1B587A5100552FC2 /* Products */, diff --git a/Storage/Disk/Controller/DiskController.cpp b/Storage/Disk/Controller/DiskController.cpp index 8c69c1335..0cc708748 100644 --- a/Storage/Disk/Controller/DiskController.cpp +++ b/Storage/Disk/Controller/DiskController.cpp @@ -8,7 +8,7 @@ #include "DiskController.hpp" -#include "../../../NumberTheory/Factors.hpp" +#include "../../../Numeric/Factors.hpp" using namespace Storage::Disk; diff --git a/Storage/Disk/Controller/MFMDiskController.hpp b/Storage/Disk/Controller/MFMDiskController.hpp index da8270194..34844b631 100644 --- a/Storage/Disk/Controller/MFMDiskController.hpp +++ b/Storage/Disk/Controller/MFMDiskController.hpp @@ -10,7 +10,7 @@ #define MFMDiskController_hpp #include "DiskController.hpp" -#include "../../../NumberTheory/CRC.hpp" +#include "../../../Numeric/CRC.hpp" #include "../../../ClockReceiver/ClockReceiver.hpp" #include "../Encodings/MFM/Shifter.hpp" diff --git a/Storage/Disk/DiskImage/Formats/WOZ.hpp b/Storage/Disk/DiskImage/Formats/WOZ.hpp index 6e4885de1..2e5703802 100644 --- a/Storage/Disk/DiskImage/Formats/WOZ.hpp +++ b/Storage/Disk/DiskImage/Formats/WOZ.hpp @@ -11,7 +11,7 @@ #include "../DiskImage.hpp" #include "../../../FileHolder.hpp" -#include "../../../../NumberTheory/CRC.hpp" +#include "../../../../Numeric/CRC.hpp" #include <string> 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 <cassert> #include <set> 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 <cstdint> #include <memory> -#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 <vector> #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<PCMSegment> segment_; std::size_t bit_pointer_; Track::Event next_event_; - LFSR<uint64_t> lfsr_; + Numeric::LFSR<uint64_t> 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 <cmath> #include <cstdint> #include <limits> @@ -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<unsigned int>::max() || long_clock_rate > std::numeric_limits<unsigned int>::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 <algorithm> #include <cassert>