49 Commits

Author SHA1 Message Date
Mateusz Pusz e0cc4eec90 docs(utility): document the utility component, namespace tiers, and the safe_int/constrained move
Add a Namespaces section to the project structure docs describing the three
public tiers (mp_units / mp_units::utility / mp_units::detail), show the
core -> systems -> utility module layering, and list the utility headers.
Update the representation and custom-representation guides to introduce the
built-in cartesian types via mp_units::utility, and update the safe_int /
constrained material (guide, blog posts, tutorials) to the new
<mp-units/utility/...> include paths and mp_units::utility names.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-29 18:07:49 +02:00
Mateusz Pusz 7ec072cd7b style: markdownlint-cli2 added to pre-commit 2026-06-23 23:03:04 +02:00
Mateusz Pusz 982fc526c0 feat: 💥 quantity_from_unit_zero() renamed back to quanity_from_zero() and limited to default_point_origin + qp.in(Unit) changes the origin for offset units 2026-05-21 22:46:12 +02:00
Mateusz Pusz 47fdf2254b docs: frame projections tutorial added 2026-05-13 19:13:27 +02:00
Mateusz Pusz c93778010f feat: 💥 final is not longer required for definitions and should not be used for quantity_spec 2026-05-13 15:23:47 +02:00
Mateusz Pusz 4161608a92 docs: point origin inheritance docs added 2026-05-06 22:35:58 +02:00
Mateusz Pusz 0de0438d76 docs: '?' removed from headers with nominal clauses 2026-04-30 15:57:07 +02:00
René Paris df8c264e24 Fix quantity calculation from subtraction to addition 2026-04-28 19:33:36 +02:00
Mateusz Pusz 0a33e0a0e6 refactor: quantity point bounds are now specified directly in origin - quantity_bounds_for customization point removed 2026-04-25 21:00:31 +02:00
Mateusz Pusz 4b19dc2bf2 docs: simple change in the calulator tutorial source code 2026-04-11 20:31:10 +02:00
Mateusz Pusz a1e1e7cb21 feat: non-negative quantities support added
Resolves #468
2026-04-06 22:51:42 +02:00
Mateusz Pusz c30a637ae7 refactor: 💥 zeroth-names deprecated; quantity_from_unit_zero(); natural_point_origin 2026-03-31 22:03:03 +02:00
Mateusz Pusz c7064f73f4 docs: minor documentation improvements 2026-03-24 09:54:18 +00:00
Mateusz Pusz efbc844199 fix: fixed-point arithmetic for integer unit conversions (#580) (#764)
* Fix #580: use fixed-point arithmetic for integer unit conversions

Introduce a fixed-point implementation for unit conversions involving
integer representations, avoiding loss of significant digits that
previously occurred when the conversion factor was not a whole number.

New files:
- src/core/include/mp-units/bits/fixed_point.h: double_width_int<T> and
  fixed_point<T,n> types for exact rational scaling of integer values.
  Uses __int128 when available (__SIZEOF_INT128__) for 64-bit integers.
- src/core/include/mp-units/framework/scaling.h: public scaling_traits<>
  customization point and scale<To>(M, value) free function. Provides
  built-in specializations for floating-point and integer-like types.
- test/static/fixed_point_test.cpp: static assertions for the new types.
- test/runtime/fixed_point_test.cpp: runtime arithmetic edge-case tests.

Modified:
- sudo_cast.h: replace hand-rolled conversion_value_traits / sudo_cast_value
  machinery with a single scale<To::rep>(c_mag, ...) call.
- representation_concepts.h: add MagnitudeScalable concept; replace
  ComplexScalar with HasComplexOperations (which is its definition).
- customization_points.h: add unspecified_rep tag and declare the primary
  scaling_traits<> template.
- framework.h / CMakeLists.txt: wire in the new headers.
- hacks.h: add MP_UNITS_DIAGNOSTIC_IGNORE_PEDANTIC and
  MP_UNITS_DIAGNOSTIC_IGNORE_SIGN_CONVERSION macros.
- example/measurement.cpp: add scaling_traits specializations for
  measurement<T> to demonstrate the customization point.
- test/static/{international,usc}_test.cpp: disable two tests that are
  blocked on issue #614.

Co-authored-by: Tobias Hanhart <burnpanck@users.noreply.github.com>

* Fix value_Type typo in floating_point_scaling_factor_type specialization

The partial specialization for types with a nested value_type used
'value_Type' (capital T) instead of 'value_type', making the entire
specialization dead code as the requires-clause could never be satisfied.

Also fix 'mantiassa' -> 'mantissa' in the adjacent comment.

* Fix docstring typos in scaling_traits documentation

- 'quantitiy' -> 'quantity'
- 'dictatet' -> 'dictated'
- 'convetrible' -> 'convertible'
- 'implemenation' -> 'implementation'
- 'availabe' -> 'available'

* Fix conflict resolution error: keep ComplexScalar name from master

When resolving the merge conflict in representation_concepts.h, the
PR's renamed version of the concept ('HasComplexOperations') was used
instead of master's established name ('ComplexScalar'). The two concepts
are semantically equivalent — burnpanck simply renamed it in his branch.

Revert to the canonical 'ComplexScalar' name while retaining the new
'MagnitudeScalable' concept which was the actual addition from the PR.

* Fix measurement.cpp: remove duplicate class definition from merge

The PR branched from a version where measurement<T> was defined inline
in measurement.cpp. Master later moved the class to example/include/
measurement.h and changed measurement.cpp to #include that header.

The squash merge therefore introduced a duplicate definition: the class
from the header and the PR's inline class were both visible, causing
an 'ambiguous reference' error. Remove the now-redundant inline class;
the scaling_traits specializations added by the PR work correctly with
the class from measurement.h.

* style: pre-commit

* docs: chapters anchors improved in the "custom representation" chapter

* docs: value conversions chapter improved

* refactor: scaling support refactored

* fix: clang-16 crash fixed

* docs: `measurement` example documentation updated to match changes

* fix: use exact wide-integer arithmetic for rational unit conversions on all platforms

On ARM / Apple Silicon, long double == double (64-bit mantissa).  The old
fixed_point<T>(long double) initialiser lost ~12 bits of precision for 64-bit
integer types when representing the scaling ratio, producing an error of ~49
units for the 10/9 (degree → gradian) conversion with a 10^18 input value.

Fix by splitting the integer-path else-branch into two cases:

  • Pure rational M (is_integral(M * (denominator(M) / numerator(M))) == true):
    use (value * numerator) / denominator via double_width_int_for_t<> arithmetic.
    This is exact on every platform regardless of long double width.

  • Irrational M (involves π etc.): keep the long double fixed_point approximation.
    These conversions are inherently approximate; small values still produce correct
    truncated results on all platforms.

Update the test comment to reflect the new exact-arithmetic path.

Fixes CI failures on clang-18/ARM and apple-clang-16.

* fix: replace floating-point TeX-point test with exact integer equivalent

72.27 is not exactly representable as double (it rounds to 72.2699...96).
Multiplying by the conversion factor 100/7227 via long double gives a result
≥ 1.0 on x86 (80-bit long double, 64-bit mantissa) only by chance, but
0.99999...978 on ARM / Apple Silicon where long double == double (52-bit).

The correct mathematical statement is: 7227 tex_point = 100 inch (exact
rational relationship).  Use that integer form instead of the inexact 72.27
double literal so the test is correct and platform-independent.

---------

Co-authored-by: Tobias Hanhart <burnpanck@users.noreply.github.com>
2026-03-07 21:02:37 +01:00
Mateusz Pusz 4bc3b3871b docs: reference for HEP specialized quantities added 2026-02-22 01:02:07 +01:00
Mateusz Pusz e7e8c36d57 style: pre-commit 2026-01-25 23:02:33 +01:00
Mateusz Pusz f097d96946 docs: large docs update (new tutorials, index pages) 2026-01-25 22:15:23 +01:00
Mateusz Pusz 445c69dc4a docs: tutorials renamed to workshops 2026-01-25 08:23:57 +01:00
Mateusz Pusz cd36c901f1 docs: "What you learned?" chapter added to all tutorials 2026-01-22 19:37:42 +01:00
Mateusz Pusz d6fc474deb docs: "Strongly-Typed Counts" tutorial added 2026-01-21 23:37:24 +01:00
Mateusz Pusz 0a5b2d9c32 docs: "Takeaways" chapter refactored in the migration tutorial 2026-01-19 12:27:37 +01:00
Mateusz Pusz a5a15cbb30 docs: "Working with Legacy Interfaces" description changed in tutorial 2026-01-19 12:25:50 +01:00
Mateusz Pusz efc12fe780 docs: "References" and "Takeaways" chapters reordered in the migration tutorial 2026-01-19 12:22:02 +01:00
Mateusz Pusz c7b57a1a85 docs: incremental migration tutorial added 2026-01-19 12:18:19 +01:00
Mateusz Pusz 9c5f2412bc refactor: 💥 international system renamed to yard_pound 2026-01-14 12:21:45 +01:00
Mateusz Pusz adda270c33 docs: a large refactoring of TOC
Some chapters moved to the top level and other moved to other places
2026-01-14 09:56:52 +01:00
Mateusz Pusz aae4354201 docs: tutorials renamed to use stable names 2026-01-13 17:10:28 +01:00
Mateusz Pusz 57381cf991 docs: "Use Cases" renamed to "How-to Guides" 2026-01-13 17:00:49 +01:00
Mateusz Pusz e6c2f64c73 style: pre-commit 2026-01-12 20:22:51 +01:00
Mateusz Pusz 7d12d4aa20 docs: tutorials 11 and 12 swapped in order 2026-01-12 20:19:32 +01:00
Mateusz Pusz 35d6ef3669 docs: tutorial 12 added 2026-01-12 20:16:43 +01:00
Mateusz Pusz 9a374a5646 refactor: isq::time swapped with isq::duration 2026-01-09 09:22:37 +01:00
Mateusz Pusz 698640dccf style: pre-commit 2026-01-05 20:19:32 +01:00
Mateusz Pusz 98be73f0f6 docs: tutorial 11 added 2026-01-05 19:17:16 +01:00
Mateusz Pusz 39ad14a751 docs: "Introduction" chapter removed from tutorial 8 2026-01-05 18:58:34 +01:00
Mateusz Pusz fdd76d5bd8 docs: tutorial 7 structure unified with other tutorials 2026-01-05 18:58:08 +01:00
Mateusz Pusz 4fdd6457d8 docs: broken link to "Tutorial 7" fixed 2026-01-04 12:20:06 +01:00
Mateusz Pusz bd694819a3 style: pre-commit 2026-01-04 10:07:29 +01:00
Mateusz Pusz 31e112ae22 docs: tutorial 10 added 2026-01-03 20:49:36 +01:00
Mateusz Pusz 6bb179adce docs: tutorial 9 added 2025-12-29 13:06:45 +01:00
Mateusz Pusz d6dc00db5e docs: tutorials 7 and 8 swapped in order 2025-12-29 13:05:25 +01:00
Mateusz Pusz 23d91ff8be docs: "References" chapter added to all tutorials 2025-10-17 10:45:04 +02:00
Mateusz Pusz d864da87e2 docs: ce_embed script now also takes mp-units version as an argument 2025-10-17 10:04:25 +02:00
Mateusz Pusz 499093100a docs: solution of tutorial 8 fixed 2025-10-17 09:25:57 +02:00
Mateusz Pusz 9c5d9f748f docs: tutorial 8 improved again 2025-10-16 14:19:24 +02:00
Mateusz Pusz 932f354d4f docs: tutorial 8 added 2025-10-16 10:39:18 +02:00
Mateusz Pusz 76abb8fee6 docs: tutorial 7 added 2025-10-15 11:26:55 +02:00
Mateusz Pusz 0e0751a2c2 style: pre-commit 2025-10-14 18:25:58 +02:00
Mateusz Pusz 3d6149acbf docs: first tutorials added 2025-10-14 18:25:58 +02:00