Commit Graph
96 Commits
Author SHA1 Message Date
Oliver Schönrock 39a2c2de0e employing more mathemtaically correct ratio_gcd calc (for common ratio)
really finds the maximum common ration as opposed to previous algo which
simplified on the exp part of the ratio by using std::min
most of new code credit to Conor Williams
discussion and additional doc here:
https://github.com/mpusz/units/issues/62#issuecomment-588152833
test case was 1yd + 1in = 37in => added as a test
commenting out unusued ratio_add and its tests
if to be reintroduced, should also use the new gcd routines
additonal change was required to check in `safe_divisible` concept
den=1 is not sufficient anymore. reusing new gcd routines
moved ratio nomalize and new gcd routines into new, separate bits/ratio_maths.h
this resolves #62
2020-02-20 19:59:12 +01:00
Mateusz Pusz 3be8ee921e Starship improvements after the latest gcc fixes 2020-02-12 09:48:04 +01:00
Oliver Schönrock 23d44c1b4a implementing our own (very limited) std::pow functions
integer and float treated separately
perhaps not ideal, but not obvioius what would be clearly better
2019-12-28 17:59:47 +01:00
Oliver Schönrock 0ad78fe753 small changes based on code review 2019-12-28 17:59:47 +01:00
Oliver Schönrock 509b6c9653 implementing ratio<num,den,exp> which replaces ratio<num,den>
https://github.com/mpusz/units/issues/14

This "works", as in it passes all static and runtime tests.
However quite a few of the tests have been "modified" to make them pass. Whether
this is legitimate is debatable and should be the source of some thought /
discussion.

1. many of the static tests and some of the runtime tests have had the input
ratios of the tests modified in the following way. eg ratio<3,1000> =>
ratio<3,1,-3>. ie they have been "canonicalised".

There are obviously an infinite number of ratios which represent the same
rational number. The way `ratio` is implemented it always moves as "many powers
of 10" from the `num` and `den` into the `exp` and that makes the `canonical`
ratio.

Because these are all "types" and the lib uses is_same all over the place, only
exact matches will be `is_same`. ie ratio<300,4,0> !is_same ratio<3,4,2> (the
latter is the canonical ratio). This is perhaps fine for tests in the devlopment
phase, but there may be a need for "more forgiving" comparison / concept of
value equality. One such comparison which compares den,num,exp after
canonicalisation is the constexpr function `same` as defined at top of
`ratio_test.cpp`. We may need to expose this and perhaps add even more soft
comparisions.

2. In the runtime tests it is "subjective" how some resukts should be
printed. There is the question of "how exactly to format certain ratios". eg
omit denominators of "1" and exponents of "0". However before even addressing
these in detail a decision needs to be made about the general form of
"non-floating-point-converted" ratios which do not map exactly to a "Symbol
prefix".

Arguably these are "relatively ugly" whatever we do, so we could just
go for an easily canonicalised form. An example is:

-        CHECK(stream.str() == "10 [1/60]W");
+        CHECK(stream.str() == "10 [1/6 x 10⁻¹]W");

Which of thses is "better"? Is there a "third", better form?  It's not obvious.

My opnion is: Both of 1&2 are fine for now, unless we think they go down the
wrong avenue, and can be "perfected later"? ie we can expose a softer version of
ratio based equality, and decide on canonical way of printing ratios (as far as
that is actually a very useful output form, compared with decimal, scientific or
engineering notation).
2019-12-28 17:59:47 +01:00
Mateusz Pusz 3decaecb52 TODO comments clean-up 2019-12-17 20:15:38 +01:00
Mateusz Pusz fbf3ef8c4f Most of concepts moved to a new file + quantity.h split to smaller pieces 2019-12-12 13:17:31 +01:00
Mateusz Pusz 9d50ea6ab5 CGS case added to avg_speed example 2019-12-11 21:38:44 +01:00
Mateusz Pusz 71f38222ea Implicit conversions fixed 2019-12-11 16:16:05 +01:00
Mateusz Pusz 5a7324596d Resulting unit ratio fixed in arithmetic operations 2019-12-11 13:31:40 +01:00
Mateusz Pusz c3c80fde11 Spaceship support added (resolves #19) 2019-12-11 11:27:51 +01:00
Mateusz Pusz e472fdc348 Most of the operators converted to hidden friends 2019-12-11 10:44:55 +01:00
Mateusz Pusz bc1901f4f0 Text formatting enabled + directory tree refactoring 2019-12-11 08:07:13 +01:00
Mateusz Pusz 8ffc46ba75 CGS support added 2019-12-09 17:19:58 +01:00
Mateusz Pusz 7619a6f831 gcc-10 crash fixed 2019-12-08 21:57:06 +01:00
Mateusz Pusz 6b4220100f quantity_cast refactored
- new version with ToD added
- <ToU, Rep> version removed
2019-12-08 16:24:29 +01:00
Mateusz Pusz 22eda11bea More refactoring
- unknown_unit and unknown_dimension added
- the support for remaining SI units added
2019-12-07 16:30:40 +01:00
Mateusz Pusz f31b26b5e5 Design cleanup
- unknown_unit added
- examples refactored
- base_type renamed to downcast_base_type
- scaled_unit renamed to named_scaled_unit
- detail::reference_unit renamed to scaled_unit
- quantity_test cleanup
2019-12-06 12:18:39 +01:00
Mateusz Pusz c48bfe2098 quantity refactored and quantity_test enabled 2019-12-04 17:46:19 +01:00
Mateusz Pusz 3d2c613dcb quantity operators * and / constrains weaken to one magma 2019-11-16 18:29:32 +01:00
Mateusz Pusz d4976caf1d operator- constraints fixed 2019-11-16 18:28:13 +01:00
Mateusz Pusz 9c6229302d Small code cleanup 2019-11-16 18:27:31 +01:00
Mateusz Pusz 57e464cc99 quantity constraints refactored 2019-11-15 20:20:25 +01:00
Mateusz Pusz 2328a26992 Downcasting support added to quantity_cast (resolves #26) 2019-11-09 14:42:06 +00:00
Mateusz Pusz 4d1e225d9e UnitRep renamed to QuantityRep 2019-11-09 14:16:37 +00:00
Mateusz Pusz 04cbeb841e Disabled prefix/postfix increment/decrement operators (resolves #18) 2019-11-09 14:09:30 +00:00
Mateusz Pusz ad895b4651 Small refactoring of QuantityOf 2019-11-08 14:35:18 +00:00
Mateusz Pusz 9871cf0ed7 UnitRep extended 2019-11-06 21:51:40 +00:00
Mateusz Pusz e4cd4ea8c8 UnitRep concept introduced 2019-11-06 20:17:16 +00:00
Mateusz Pusz b5b2c54fe8 Basic std::fmt support added 2019-11-05 20:05:11 +00:00
Mateusz Pusz 91bcfedf1e Deduced units symbols refactoring started 2019-11-04 06:45:56 +00:00
Mateusz Pusz 7da63eedfd quantity refactoring 2019-11-02 13:58:10 +01:00
Mateusz Pusz 2bde0e62b2 Downcasting facility refactoring 2019-11-02 13:54:43 +01:00
Mateusz Pusz 53720c82b8 fmt support started 2019-10-18 23:50:43 +02:00
Mateusz Pusz b864461636 Prefixed units support redesigned 2019-10-18 15:34:46 +02:00
Mateusz Pusz 95028d10a7 gcc-10 enabled 2019-10-17 18:22:51 +02:00
Mateusz Pusz 3e30c779a6 coherent_derived_unit and custom prefixes support added 2019-10-17 10:16:44 +02:00
Mateusz Pusz 9a9abca81d Text output support added for quantity 2019-10-16 17:04:41 +02:00
Mateusz Pusz fa2bdd1e08 More 'todo' -> 'TODO' changes 2019-10-15 21:20:01 +02:00
Mateusz Pusz 2bcc5fa4e5 Small quantity formatting cleanup with clang-format 2019-10-15 11:29:25 +02:00
Mateusz Pusz 040c703461 Scalar constraint added for quantity operators 2019-10-08 21:26:18 +02:00
Mateusz Pusz 458ac0918b Scalar constraint added to quantity constructor 2019-10-08 21:20:37 +02:00
Mateusz Pusz 4ba818bb78 quantity_cast_impl refactored to use compile time branching rather than concepts 2019-10-08 21:20:06 +02:00
Mateusz Pusz 3f8cee0931 Scalar concept constraints reversed 2019-10-08 21:19:04 +02:00
Mateusz Pusz 2fddb494d3 _t postfix removed from the interface (resolves #9) 2019-10-04 16:22:49 +02:00
Mateusz Pusz 7c4e5d086a Merge pull request #17 from jansende/patch-2
Optimized floating point unit conversions
2019-10-01 20:08:01 +02:00
Mateusz Pusz 12200f6f40 operator% constrained to integral types only (resolves #16) 2019-10-01 16:29:42 +02:00
Jan Sende a11f5a92b6 Optimized floating point unit conversions
- Divisions are now made at compile time.
- Only runtime multiplications are left.
2019-09-30 23:38:33 +02:00
Mateusz Pusz f373adb42f Not needed static_assert removed from quantity class template 2019-09-30 09:07:15 +02:00
Mateusz Pusz f9d6b53b72 [[nodiscard]] added to quantity_cast and DESIGN.md update with the new quantity_cast functionality 2019-09-30 09:05:50 +02:00