From d3189acaa63caf048025794aa3b0fb8f87faf6f6 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 1 Jan 2022 17:14:52 -0500 Subject: [PATCH] Add a constexpr route that explicitly calculates the simplest possible form. --- Storage/Storage.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Storage/Storage.hpp b/Storage/Storage.hpp index f096e63bb..90db2b5cd 100644 --- a/Storage/Storage.hpp +++ b/Storage/Storage.hpp @@ -33,6 +33,10 @@ struct Time { Time(float value) { install_float(value); } + static constexpr Time simplified(unsigned int _length, unsigned int _clock_rate) { + const auto gcd = std::gcd(_length, _clock_rate); + return Time(_length / gcd, _clock_rate / gcd); + } /*! Reduces this @c Time to its simplest form; eliminates all common factors from @c length