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/Factors.hpp b/NumberTheory/Factors.hpp deleted file mode 100644 index 36321fdd0..000000000 --- a/NumberTheory/Factors.hpp +++ /dev/null @@ -1,50 +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 NumberTheory { - /*! - @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 - } - - /*! - @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) { - if(a == b) return a; - - T gcd = greatest_common_divisor(a, b); - return (a / gcd) * (b / gcd) * gcd; - } -} - -#endif /* Factors_hpp */ 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/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..7fc441f4c 100644 --- a/Storage/Disk/Track/PCMTrack.cpp +++ b/Storage/Disk/Track/PCMTrack.cpp @@ -7,7 +7,6 @@ // #include "PCMTrack.hpp" -#include "../../../NumberTheory/Factors.hpp" #include "../../../Outputs/Log.hpp" using namespace Storage::Disk; diff --git a/Storage/Storage.hpp b/Storage/Storage.hpp index 01f7129a8..92d42ca70 100644 --- a/Storage/Storage.hpp +++ b/Storage/Storage.hpp @@ -9,10 +9,10 @@ #ifndef Storage_hpp #define Storage_hpp -#include "../NumberTheory/Factors.hpp" #include #include #include +#include namespace Storage { @@ -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 = 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 = NumberTheory::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/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..c14c1b4ce 100644 --- a/Storage/Tape/Tape.cpp +++ b/Storage/Tape/Tape.cpp @@ -7,7 +7,6 @@ // #include "Tape.hpp" -#include "../../NumberTheory/Factors.hpp" using namespace Storage::Tape; diff --git a/Storage/TimedEventLoop.cpp b/Storage/TimedEventLoop.cpp index aba194ae2..2fa932ff9 100644 --- a/Storage/TimedEventLoop.cpp +++ b/Storage/TimedEventLoop.cpp @@ -7,7 +7,6 @@ // #include "TimedEventLoop.hpp" -#include "../NumberTheory/Factors.hpp" #include #include