Quantify
An extensible C++ units library
Loading...
Searching...
No Matches
frac.cppm
Go to the documentation of this file.
1// Copyright (c) 2024-2025, Víctor Castillo Agüero.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16module;
18export module quantify.core:frac;
19import std;
20import :preface;
21
22export namespace quantify {
23 template<typename Numerator, typename Denominator>
24 struct frac {
25 UNIT_SYMBOL("(" + Numerator::symbol() + ")/(" + Denominator::symbol() + ")")
26 };
27
28 template<typename Numerator, typename Denominator>
29 requires requires {
30 typename Numerator::scale;
31 typename Denominator::scale;
32 }
33 struct frac<Numerator, Denominator> {
35
36 template<typename T>
37 using factor = ratio<
38 T,
39 (long)(Numerator::template factor<T>::numerator * Denominator::template factor<T>::denominator),
40 (long)(Numerator::template factor<T>::denominator * Denominator::template factor<T>::numerator)
41 >;
42
43 UNIT_SYMBOL("(" + Numerator::symbol() + ")/(" + Denominator::symbol() + ")")
44 };
45}
#define UNIT_SYMBOL(...)
Definition unit_macros.h:18
Core components of the Quantify library.
ratio< T,(long)(Numerator::template factor< T >::numerator *Denominator::template factor< T >::denominator),(long)(Numerator::template factor< T >::denominator *Denominator::template factor< T >::numerator) > factor
Definition frac.cppm:37
frac< typename Numerator::scale, typename Denominator::scale > scale
Definition frac.cppm:34
Static representation of a numerical ratio in the form of a fraction.
Definition ratio.cppm:26
static constexpr T numerator
Definition ratio.cppm:27
static constexpr T denominator
Definition ratio.cppm:28