file
Ratio.hThis module provides lossless methods for dealing with exact fractions.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Classes
Typedefs
Functions
- CnxRatio cnx_ratio_new(i64 num, i64 den)
- Constructs a
CnxRatio
- CnxRatio cnx_ratio_add(CnxRatio lhs, CnxRatio rhs)
- Adds the given
CnxRatio
s. - CnxRatio cnx_ratio_subtract(CnxRatio lhs, CnxRatio rhs)
- Subtracts the given
CnxRatio
s. - CnxRatio cnx_ratio_multiply(CnxRatio lhs, CnxRatio rhs)
- Multiplies the given
CnxRatio
s. - CnxRatio cnx_ratio_divide(CnxRatio lhs, CnxRatio rhs)
- Divides the given
CnxRatio
s. - bool cnx_ratio_equal(CnxRatio lhs, CnxRatio rhs)
- Returns whether the two
CnxRatio
s are equal. - bool cnx_ratio_not_equal(CnxRatio lhs, CnxRatio rhs)
- Returns whether the two
CnxRatio
s are not equal. - bool cnx_ratio_less_than(CnxRatio lhs, CnxRatio rhs)
- Returns whether the left-hand
CnxRatio
is less than the other. - bool cnx_ratio_less_than_or_equal(CnxRatio lhs, CnxRatio rhs)
- Returns whether the left-hand
CnxRatio
is less than or equal to the other. - bool cnx_ratio_greater_than(CnxRatio lhs, CnxRatio rhs)
- Returns whether the left-hand
CnxRatio
is greater than the other. - bool cnx_ratio_greater_than_or_equal(CnxRatio lhs, CnxRatio rhs)
- Returns whether the left-hand
CnxRatio
is greater than or equal to the other. - CnxCompare cnx_ratio_compare(CnxRatio lhs, CnxRatio rhs)
- Returns the comparison of the left-hand
CnxRatio
to the other. - CnxOption(i64)
- Returns the given
CnxRatio
as a scalar value. - f64 cnx_ratio_as_scalar(CnxRatio ratio)
- Returns the given
CnxRatio
as a scalar value. - CnxRatio cnx_ratio_add_scalar(CnxRatio ratio, i64 scalar)
- Adds the given ratio and scalar value.
- CnxRatio cnx_ratio_subtract_scalar(CnxRatio ratio, i64 scalar)
- Subtracts the given scalar value from the given ratio.
- CnxRatio cnx_ratio_multiply_scalar(CnxRatio ratio, i64 scalar)
- Multiplies the given ratio and scalar value.
- CnxRatio cnx_ratio_divide_scalar(CnxRatio ratio, i64 scalar)
- Divides the given ratio by the given scalar value.
- CnxFormatContext cnx_ratio_is_specifier_valid(const CnxFormat*restrict self, CnxStringView specifier) cnx_disable_if(!self
- Implementation of
CnxFormat.is_specifier_valid
forCnxRatio
- CnxString cnx_ratio_format(const CnxFormat*restrict self, CnxFormatContext context) cnx_disable_if(!self
- Implement
CnxFormat.format
forCnxRatio
- CnxString cnx_ratio_format_with_allocator(const CnxFormat*restrict self, CnxFormatContext context, CnxAllocator allocator) cnx_disable_if(!self
- Implement
CnxFormat.format_with_allocator
forCnxRatio
-
static ImplTraitFor(CnxFormat,
CnxRatio,
cnx_
ratio_ is_ specifier_ valid, cnx_ ratio_ format, cnx_ ratio_ format_ with_ allocator) - Implement
CnxFormat
forCnxRatio
Defines
- #define CNX_RATIO
- Declarations related to
CnxRatio
- #define cnx_ratio(numerator, denominator)
- Constructs a
CnxRatio
at compile time. - #define cnx_atto
- SI "atto" as a
CnxRatio
- #define cnx_femto
- SI "femto" as a
CnxRatio
- #define cnx_pico
- SI "pico" as a
CnxRatio
- #define cnx_nano
- SI "nano" as a
CnxRatio
- #define cnx_micro
- SI "micro" as a
CnxRatio
- #define cnx_milli
- SI "milli" as a
CnxRatio
- #define cnx_centi
- SI "centi" as a
CnxRatio
- #define cnx_deci
- SI "deci" as a
CnxRatio
- #define cnx_deca
- SI "deca" as a
CnxRatio
- #define cnx_hecto
- SI "hecto" as a
CnxRatio
- #define cnx_kilo
- SI "kilo" as a
CnxRatio
- #define cnx_mega
- SI "mega" as a
CnxRatio
- #define cnx_giga
- SI "giga" as a
CnxRatio
- #define cnx_tera
- SI "tera" as a
CnxRatio
- #define cnx_peta
- SI "peta" as a
CnxRatio
- #define cnx_exa
- SI "exa" as a
CnxRatio
Function documentation
CnxFormatContext cnx_ratio_is_specifier_valid(const CnxFormat*restrict self, CnxStringView specifier) cnx_disable_if(!self
Implementation of CnxFormat.is_specifier_valid
for CnxRatio
Parameters | |
---|---|
self | - The CnxRatio to format as a CnxFormat trait object |
specifier | - The CnxStringView viewing the format specifier to validate |
Returns | The CnxFormatContext indicating whether specifier was valid and storing the state holding the format settings and necessary info to format the CnxRatio |
CnxString cnx_ratio_format(const CnxFormat*restrict self, CnxFormatContext context) cnx_disable_if(!self
Implement CnxFormat.format
for CnxRatio
Parameters | |
---|---|
self | - The CnxRatio to format |
context | - The CnxFormatContext specifying how formatting should be done |
Returns | self formatted as a CnxString |
CnxString cnx_ratio_format_with_allocator(const CnxFormat*restrict self, CnxFormatContext context, CnxAllocator allocator) cnx_disable_if(!self
Implement CnxFormat.format_with_allocator
for CnxRatio
Parameters | |
---|---|
self | - The CnxRatio to format |
context | - The CnxFormatContext specifying how formatting should be done |
allocator | - The allocator to allocate memory for the formatted string with |
Returns | self formatted as a CnxString |