Commit Graph
467 Commits
Author SHA1 Message Date
Chip Hogg 59fa420272 Fix remaining builds/tests 2022-05-12 16:52:05 +00:00
Chip Hogg 5fb468697b Merge branch 'master' into chiphogg/switch-to-mag 2022-05-12 16:12:01 +00:00
Mateusz Pusz 5300caf17b refactor: 💥 ! derived_deduced_unit renamed to derived_scaled_unit
Naming is hard ;-)
2022-05-11 12:34:52 +02:00
Mateusz Pusz 32b36fb670 refactor: 💥 ! PrefixFamily support removed
It doesn't have much sense to restrict prefixes usage for most units and in many places we were wrong to do so already.
2022-05-11 11:59:33 +02:00
Mateusz Pusz 0522bae972 refactor: 💥 ! unit renamed to derived_unit 2022-05-11 11:40:19 +02:00
Mateusz Pusz f5d21a0711 refactor: 💥 ! derived_unit renamed to derived_deduced_unit 2022-05-11 11:23:18 +02:00
Mateusz Pusz 4c60447a28 Merge branch 'master' into downcast_mode_off 2022-05-09 19:12:02 +02:00
Mateusz Pusz ffa0f321f9 fix: shadowing compilation errors on MSVC fixed 2022-05-06 10:00:39 +02:00
Mateusz Pusz 4361cb874e fix: hectare definition fixed to be a prefixed version of are + other units
Relates to #359
2022-04-27 19:32:21 +02:00
Mateusz Pusz 56cee31a67 fix: si::hep::dim_momentum duplicated definition fixed 2022-04-24 19:52:07 +02:00
Mateusz Pusz a0c6252567 refactor: mi(naut) renamed to nmi
Relates to #357
2022-04-19 18:47:48 +02:00
Chip Hogg 2b37bc7b3e Address review feedback 2022-04-19 15:42:43 +00:00
Chip Hogg 78bcb3b019 Remove troublesome ::ratio members
For some reason, MSVC seems to want to instantiate these, even though
nobody ever asks for them (as evidenced by the fact that the builds
passed on other architectures).
2022-04-12 00:35:17 +00:00
Chip Hogg 5e365f1905 Delete obsolete test case 2022-04-11 15:16:16 +00:00
Chip Hogg d19b2803ce Migrate units from ratio to Magnitude
This commit is huge, but hopefully the cognitive load is not too bad.
The bulk of this commit is just some fairly mechanical updates from
`ratio` to `Magnitude`.  Other things to call out:

- `UnitRatio` goes away.  We don't need this concept, because Magnitude
  can't even _represent_ anything that doesn't satisfy it.

- I commented out some formatting test cases where the precise
  expression changes, but the number is completely equivalent.  We will
  need to decide how we want to handle Magnitude formatting as a
  separate, follow-on task.  But at least Magnitude gives us all the
  tools we'll need to do so!
2022-04-11 15:16:16 +00:00
Chip Hogg af8eec1102 Implement "common Magnitude" of two Magnitudes 2022-04-11 15:16:15 +00:00
Chip Hogg 2c31bf83ec Clean up 2022-04-06 02:01:23 +00:00
Chip Hogg b616e58216 Give up on implicit conversion
I don't understand what MSVC is complaining about, and it may end up
being easier to just make the conversion explicit.
2022-04-06 01:40:17 +00:00
Chip Hogg 0f776b5b5b Remove incorrectly included test
We had removed this upstream, but apparently it snuck back in from a merge/rebase conflict.
2022-04-06 00:31:18 +00:00
Chip Hogg d7681e188e Support seamless interop between ratio and rational Magnitude
We provide two new functions, `numerator(m)` and `denominator(m)`, for a
Magnitude `m`.  They fulfill the following conditions:

1. `numerator(m)` and `denominator(m)` are always integer Magnitudes.
2. If `m` is rational, then `m == numerator(m) / denominator(m)`.

If `m` is _not_ rational, then the numerator and denominator are not
especially meaningful (there is no uniquely defined "leftover irrational
part").  However, we choose a convention that matches how humans would
write a mixed number.  For example, sqrt(27/16) would have a numerator
of 3, denominator of 4, and a "leftover part" of sqrt(3), matching the
"human" way of writing this as [(3 * sqrt(3)) / 4].  This has no use
yet, but it may later be useful in printing the Magnitude of an
anonymous Unit for end users.

To further reduce friction for the upcoming migration, we provide an
implicit conversion from a Magnitude to a `ratio`.  We restrict this
operation to rational Magnitudes, and guard this with a `static_assert`.
2022-04-05 23:03:44 +00:00
Mateusz Pusz b221dace3f style: clang-format applied to the remaining files 2022-04-02 21:36:42 +02:00
Markus Hofbauer cf7a7ed17a check: run pre-commit on all files 2022-04-02 18:58:23 +02:00
Johel Ernesto Guerrero Peña 146f1d1c83 fix: improve downcast mode off 2022-03-28 10:58:02 -04:00
Mateusz Pusz 63f3dd2be6 Merge pull request #344 from JohelEGP/quotient_remainder_theorem
test(static): simplify quotient_remainder_theorem test cases
2022-03-22 10:04:49 +01:00
Johel Ernesto Guerrero Peña feb1a0b860 test(static): simplify quotient_remainder_theorem test cases 2022-03-21 14:29:50 -04:00
Mateusz Pusz 3729a9fe93 Merge pull request #337 from chiphogg/chiphogg/prime-wheel
Use wheel factorization for prime numbers
2022-03-21 10:37:05 +01:00
Chip Hogg 438feb3001 Remove offending unit test
Apparently, the constexpr depth which clang and MSVC can handle is too
shallow for me to write a unit test that works on all supported
compilers.
2022-03-19 17:05:55 +00:00
Chip Hogg 0f80c10104 Try "gentler" test case
I verified that we hit GCC 10's constexpr limit with
`wheel_factorizer<1>`, but pass with `wheel_factorizer<4>`.  I hope this
number is enough smaller than the square root of the previous value that
the other compilers will be able to handle it.  If not: we'll go lower.
2022-03-19 16:58:43 +00:00
Chip Hogg c339383873 Convert names to standard_case 2022-03-19 16:07:39 +00:00
Chip Hogg 48b6280486 Merge branch 'master' into chiphogg/prime-wheel 2022-03-19 16:01:32 +00:00
Chip Hogg 166dd1e944 Work around numbers with very large first factors
We introduce the `known_first_factor` variable template.
2022-03-19 15:56:12 +00:00
Chip Hogg a99e5f9032 Switch tests to use top-level, anonymous namespace 2022-03-19 15:54:29 +00:00
Chip Hogg 28c4fe3c08 Run clang-format-15 on changed files 2022-03-19 14:29:11 +00:00
Chip Hogg 1e8460d401 Revert "Try upping the basis size further"
This reverts commit 87073856a7.
It didn't fix the problem, and it caused some new ones.  We need a
different approach.
2022-03-19 13:21:47 +00:00
Markus Hofbauer 4c127797da check: run pre-commit on all files 2022-03-18 16:12:21 +01:00
Mateusz PuszandJohel Ernesto Guerrero Peña 6d82ddebbc Update test/unit_test/static/quantity_kind_test.cpp
Co-authored-by: Johel Ernesto Guerrero Peña <johelegp@gmail.com>
2022-03-18 08:21:15 +01:00
Mateusz Pusz 144f6951c0 style: all files refromatted with clang-format 2022-03-17 23:59:48 +01:00
Chip Hogg 87073856a7 Try upping the basis size further
We are well into a regime of diminishing returns, but we'd better start
by seeing if the easy thing works.  Besides, setting this to 7 trips the
step limit in _generating_ the algorithm!
2022-03-12 18:56:26 +00:00
Chip Hogg 73a56115a1 Fix wheel factorization algorithm 2022-03-11 03:42:19 +00:00
Chip Hogg 24b284fcbb Add tests to support claims in comment 2022-03-10 23:41:36 +00:00
Chip Hogg 04b80f0827 Use wheel factorization for prime numbers
Certain existing units in the library require very large prime
numbers---so large, in fact, that our naive trial division hits the
_iteration limit_ for `constexpr` loops.  We don't want to force users
to provide a compiler option override, so we'd better find another way.

The solution is to use the "wheel factorization" algorithm:
https://en.wikipedia.org/wiki/Wheel_factorization

This lets us skip most composite numbers in our trial division.  The
implementation presented here is configurable in terms of the size of
the "basis" of primes we use.  Bigger bases let us skip more primes, but
at the cost of storing more numbers.  Fortunately, it turns out that N=3
was good enough for our purposes.
2022-03-10 23:29:02 +00:00
Chip Hogg 7cda52af55 Merge branch 'master' into chiphogg/intmax 2022-03-01 02:30:13 +00:00
Mateusz Pusz 87ab85625b The latest Conan generates Catch2 CMake target 2022-02-28 18:27:03 +01:00
Chip Hogg 632f2785a9 Clarify section header 2022-02-24 01:48:02 +00:00
Chip Hogg 240bdd659c Use intmax for base of integral powers
I used `int` before, because it was simple, and I thought _surely_ it
would be enough.  I mean, who's going to make a unit whose magnitude has
a prime factor bigger than 32 bits?

This brings us to the "Dalton", a unit whose ratio-magnitude numerator
is 16605390666050.  The prime factorization of 16605390666050 is
(2 * 5 * 5 * 53 * 6266185157), and this last number is bigger than 2^31
by a factor of 3 or so.

Fortunately, we should have done this from the beginning anyway, because
otherwise there would be numbers we could represent in `ratio` which we
couldn't represent in `Magnitude`, and this should never be the case.
2022-02-24 01:17:27 +00:00
Mateusz Pusz 3651e199bf Merge pull request #331 from JohelEGP/llvm15
refactor: update hacks for LLVM 15
2022-02-08 10:40:31 +01:00
Johel Ernesto Guerrero Peña 3f145a25db refactor: update hacks for LLVM 15 2022-02-07 21:07:22 -04:00
Chip Hogg 7e4ab4206f Remove .value; provide free function only
This is a cleaner interface.

I also checked all of the commented-out test cases.
2022-02-06 21:53:05 +00:00
Chip Hogg dfe3db0b70 Merge branch 'master' into mag-value-t 2022-01-29 02:49:19 +00:00
Chip Hogg b36bc2b582 Turn get_value into free function 2022-01-29 02:40:51 +00:00