Commit Graph

74 Commits

Author SHA1 Message Date
Mateusz Pusz ce833d344d refactor(utility): deprecate the mp_units:: rep shims and migrate consumers
The cartesian_vector and random distribution types now live in
mp_units::utility. Turn the transitional mp_units:: shims into proper
[[deprecated]] aliases (gcc-12 keeps a plain using-declaration because
CTAD through a deprecated alias template is broken there), and migrate
all in-tree consumers to mp_units::utility:: so the deprecations don't
trip -Werror. cartesian_tensor keeps no shim: it is unreleased (added in
2.6.0, never shipped), so it lives only at mp_units::utility.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 18:55:19 +02:00
Mateusz Pusz e1c2b9562b fix(representation): key magnitude and vector decomposition on character order, support complex
`quantity::magnitude()` was constrained to an exact `quantity_character{vector}` (i.e.
`{vector, real}`), which silently excluded tensor quantities and complex vectors even though
both have a well-defined norm. It now requires `order >= vector` (vectors and tensors, any
field) plus `HasMagnitude<rep>` so the storage can actually produce one - the latter cleanly
withholds the member instead of letting the body hard-error when the rep has no magnitude.

The `magnitude` CPO gained the missing complex-scalar branch: a complex scalar is a degenerate
1D complex vector, so its magnitude is the modulus `|z|`, symmetric with the real-scalar
`std::abs` branch (a `double` standing in as a 1D real vector).

Vector decomposition (`vector_components` primary template and `ValidVectorAxes`) dropped the
real-field pin, keying on `order == vector` alone, so complex vector quantities decompose into
their complex 1D components. The order pin stays (a tensor is not a flat vector decomposition).

Adds static tests (magnitude over scalar/vector/tensor and real/complex/degenerate reps;
complex-field decomposition) asserting the intended design, and documents the complex-scalar
magnitude path in the representation-types guide.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 13:47:44 +02:00
Mateusz Pusz 703235d1d4 refactor(representation): intrinsic order/field traits and two-tier character concepts
Replace the `disable_vector`/`disable_tensor` opt-outs with intrinsic,
adapter-overridable traits and split representation classification into two tiers.

- `customization_points.h` now owns the customizable surface: the `real`/`imag`/
  `modulus` CPOs plus the `numeric_field` (field axis) and `tensor_order` (order
  axis) traits. Adapters specialize these; the derived concepts stay with the
  rest of the concept model in `representation_concepts.h`.
- `numeric_field` is the single source of truth for the field axis (default:
  `real()`/`imag()` API detection). Field matching is exact and disjoint - a real
  quantity needs a real representation and a complex one a complex representation.
- `tensor_order` is detected structurally (two-index access -> 2, one-index -> 1,
  otherwise 0) and overridable. Order matching is rank-ordered: a lower-order
  representation fills a higher-order slot.
- Character concepts (`Real`/`Complex`, rank-ordered `Scalar`/`Vector`/`Tensor`)
  carry no representation-validity, so in V3 they can also classify a quantity by
  its character. The `*Representation` concepts are `NotQuantity`-first + character
  + `UnitMagnitudeScalable`; leading with `NotQuantity` rejects a quantity before
  its operators are instantiated, avoiding a constraint-satisfaction cycle.
- Eigen/Blaze adapters declare `numeric_field` from their element type (they expose
  `real()`/`imag()` on real types too, which the API default would misread as complex).
- Rename `MagnitudeScalable` -> `UnitMagnitudeScalable` and `UsesMagnitudeAwareScaling`
  -> `UsesUnitMagnitudeAwareScaling` to disambiguate scaling by a `unit_magnitude`
  from the value/L2 magnitude (the `magnitude` CPO).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 19:17:05 +02:00
Mateusz Pusz a300614308 test: a few more quantity construction unit tests added 2026-05-21 18:45:22 +02:00
Mateusz Pusz e2e490f0cd refactor: scaling algorithm and concepts simplified 2026-04-11 19:00:33 +02:00
Mateusz Pusz d8b72fc431 refactor: scaling the value by magnitude heavily refactored 2026-03-19 00:28:15 +01:00
Mateusz Pusz cdb228d5f5 fix: cartesian_vector fixed to work properly as a representation type and enable multiply syntax 2026-03-15 07:04:02 +01:00
Mateusz Pusz 6cad11a3b9 test: remove redundant floating-point cross-unit comparison assertion
Floating-point comparisons always compile for any unit ratio; the
purpose of this block is to verify integer comparisons are SFINAE'd
out, which is already covered by no_cross_unit_int_comparison.
2026-03-08 22:19:12 +01:00
Mateusz Pusz 0eea272ece fix: overflow-safe cross-unit integer comparisons using double-width arithmetic
- Add `comparable_in_wide_type` / `CommonlyComparableQuantities` concept and
  `compare_quantities` helper in `quantity.h` that widens int reps to
  `double_width_int_for_t<Rep>` (__int128 for int64) before scaling, preventing
  silent overflow in cross-unit `operator==` / `operator<=>`
- Add `try_get_value<T>` to `unit_magnitude` returning `std::optional<T>`
  (nullopt on overflow) and refactor `get_value<T>` unsigned path to delegate
  to it; extract logic into free `try_accumulate_element<T,M>` helper taking M
  as NTTP so GCC 12 treats it as a constant expression
- Wire `scaling_overflows_non_zero_values` in `value_cast.h` through
  `try_get_value` so extreme ratios (e.g. km³ vs pm³) no longer abort at
  compile time when evaluated inside `requires`
- Add positive tests (lb vs kg, km vs mi) exercising the int64→int128 widening
  path in `yard_pound_test.cpp`
- Add negative tests using `no_cross_unit_int_comparison` template wrapper
  (necessary for soft SFINAE failure on GCC) for cubic(km)/cubic(pm),
  Zm/am (linear, factor=10^39>2^127) and cubic(mi)/cubic(pm)
2026-03-08 20:15:35 +01:00
Mateusz Pusz 6f3ef66d4b feat: comparisons against literal 0
Resolves #487
2026-02-23 11:07:22 +01:00
Mateusz Pusz 04e3d08cb9 fix: dimensionless quantitites truncation prevention fixed 2026-02-12 14:07:56 +01:00
Mateusz Pusz d194af7b97 fix: some stupid MSVC errors workarounds 2026-02-04 23:06:03 +01:00
Mateusz Pusz d74f4acc57 feat: unit_for, reference_for, and rep_for added 2026-01-28 19:28:31 +01:00
Mateusz Pusz 916a6c1a16 feat: dimensionless quantities with unit one can be created with quantity_spec::op(Val) explicit conversions 2026-01-27 20:05:58 +01:00
Mateusz Pusz 63f55959a2 feat: explicit construction from number enabled for dimensionless subkinds 2026-01-21 18:38:24 +01:00
Mateusz Pusz 9a374a5646 refactor: isq::time swapped with isq::duration 2026-01-09 09:22:37 +01:00
Mateusz Pusz 85e9a722a9 test: multiply syntax uint tests added 2026-01-07 13:29:50 +01:00
Mateusz Pusz 86e3bf5a06 fix: recursive concepts evaluation fixed
Resolves #740
2026-01-07 13:26:30 +01:00
Radnyx cc25814e82 formatting 2025-10-09 16:35:52 -07:00
Radnyx ef0e653dfe fix: seconds literal has unspecified type and depends on implementation 2025-10-09 16:35:06 -07:00
Mateusz Pusz 9c140f4b3a feat: explicit constructor now can perform an explicit quantity_spec conversion 2025-06-20 17:10:34 +02:00
Mateusz Pusz f18aa18869 refactor: compund assignment and pre-/post-increment operators are now lvalue-qualified member functions 2025-06-19 18:49:21 +02:00
Mateusz Pusz e9c5f7236e feat: ConvertibleWithNumber introduced to improve convertibility of unit one with raw numbers
Resolves #675
2025-02-11 21:28:15 +01:00
Mateusz Pusz 47a82f466c refactor: scalar and complex renamed to real_scalar and complex_scalar respectively + concepts refactoring + electromagnetism fixes 2025-02-11 17:26:19 +01:00
Mateusz Pusz 5d4e1aa740 feat: might_store_converted_common_value added to detect conversions overflowing rep
Resolves #670, resolves #671, resolves #658, resolves #303
2025-02-06 15:28:55 +01:00
Mateusz Pusz 0b14d69539 feat: quantity::one() removed
Related to #408
2025-02-05 12:08:32 +01:00
Mateusz Pusz 06cbfae3b3 feat: quantity_spec conversions improved 2024-12-28 14:02:03 +01:00
Mateusz Pusz 465f88d500 refactor: 💥 is_XXX customization points for representation types removed 2024-11-26 14:48:08 +01:00
Mateusz Pusz 9a0f7a25dd test: tests for dimensionless quantities static data members 2024-11-23 19:35:59 +01:00
Mateusz Pusz 4f8e959b5c fix(test): shadowing warnings on gcc fixed 2024-11-16 08:28:39 +01:00
Mateusz Pusz 08e94171cb test: vector quantities unit tests addded 2024-11-15 12:59:18 +01:00
Mateusz Pusz 5097096915 test: lots of tests for complex quantities 2024-11-07 18:42:20 +01:00
Mateusz Pusz da50348115 feat: 💥 RepresentationOf concept now also accepts a QuantitySpec and accepts any representation character for quantity kinds 2024-11-07 18:39:32 +01:00
Mateusz Pusz 75b50b8d2c feat: complex.h added 2024-11-07 10:58:51 +01:00
Mateusz Pusz 6896d8e086 fix: velocity is now defined in terms of displacement instead of position_vector 2024-11-06 18:46:01 +01:00
Mateusz Pusz c7303cc5fb refactor: representation concepts refactored + some quantities switched to complex 2024-11-05 19:09:16 +01:00
Mateusz Pusz f461cf479b test: test for lack of consitency between op+ and op+= for quantity_point 2024-11-04 09:41:11 +01:00
Mateusz Pusz 8ca8270d2f feat: from now on truncation is not allowed in compound assignment 2024-10-30 08:40:49 +01:00
Mateusz Pusz 18525beb31 test: small refactoring of compund assignment tests 2024-10-29 10:20:11 +01:00
Mateusz Pusz 7445585db8 fix: compound assignment operations on quantities now behave the same as on the underying representation types
Resolves #137
2024-10-29 09:18:32 +01:00
Mateusz Pusz 00847ab558 fix(tests): freestanding build fixed 2024-10-16 17:22:59 +02:00
Mateusz Pusz 21784b125e refactor: derived_quantity refactored to child_quantity 2024-10-15 21:06:52 +02:00
Mateusz Pusz 3eecdf3946 test: commutativity tests added to ISQ 2024-10-15 21:06:18 +02:00
Mateusz Pusz 569f27af8b fix: common_unit handling fixed for some corner cases 2024-10-05 17:52:52 +02:00
Mateusz Pusz 7ce8d695b1 test: std::complex-based quantities tests added 2024-09-17 12:48:13 -06:00
Mateusz Pusz 0670fbdd9f feat: value_cast<Representation, Unit>() complementary conversion function added 2024-09-13 21:38:59 +02:00
Mateusz Pusz 3d39472f46 test: unit tests for creating a quantity from a volatile variable 2024-09-06 18:07:33 +02:00
Mateusz Pusz 1570bda905 fix: quantity scaling between different prefixes improved
Resolves #608
2024-09-06 12:28:11 +02:00
Mateusz Pusz 2e840cfdb4 refactor: Repetitive inline constexpr removed as no longer needed
Not needed anymore as stated in cplusplus/draft#4601
2024-09-05 08:43:36 +02:00
Chip Hogg 3a6fac9858 Move tests to runtime 2024-07-24 20:04:15 -04:00