Commit Graph

97 Commits

Author SHA1 Message Date
Mateusz Pusz eb95325c33 feat: 💥 isq::depth removed 2026-04-25 21:03:51 +02:00
Mateusz Pusz 762a5f8c6a docs: astronomy system reference updated 2026-04-11 21:33:07 +02:00
Mateusz Pusz 19a71c1094 docs: usc system reference updated with origin for degree_Fahrenheit 2026-04-11 19:50:30 +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 dbdaa86139 docs: .cache.json updated 2026-02-28 21:34:53 +01:00
Mateusz Pusz e723823686 feat: si/core.h and si/prefix_utils.h added 2026-02-25 20:30:38 +01:00
Mateusz Pusz 7daee00226 docs: systems reference cache update 2026-02-25 15:54:59 +01:00
Mateusz Pusz a9a9e60b94 feat: wavelength should not use is_kind in the definition 2026-02-25 15:52:26 +01:00
Mateusz Pusz 23337d961b docs: systems reference updated 2026-02-24 13:40:48 +01:00
Mateusz Pusz 556f9bf839 feat: some quantities in hep and isq marked as is_kind 2026-02-24 12:07:40 +01:00
Mateusz Pusz 5653803516 docs: system reference generator fixed to handle using directives and build cross-system hierarchy trees 2026-02-24 11:33:57 +01:00
Mateusz Pusz 9a2254e0a5 feat: width and height added to hep 2026-02-23 21:54:55 +01:00
Mateusz Pusz 48ff6f9b7f docs: constants support added to systems reference generator 2026-02-23 19:33:40 +01:00
Mateusz Pusz 4bc3b3871b docs: reference for HEP specialized quantities added 2026-02-22 01:02:07 +01:00
Mateusz Pusz 6e22fab415 docs: systems reference docs updated for hep constants 2026-02-21 13:06:00 +01:00
Mateusz Pusz b109cfb380 feat: hep system refactored to be similar to the leading projects in HEP domain 2026-02-20 14:15:53 +01:00
Mateusz Pusz 9ee0d9f710 fix: normal_stress and shear_stress fixed to have stress as a parent 2026-01-31 11:33:14 +01:00
Mateusz Pusz bf601cc9b2 docs: quantity hierarchies index added 2026-01-29 17:46:50 +01:00
Mateusz Pusz 35bd1aba77 docs: another link fixed 2026-01-29 17:43:01 +01:00
Mateusz Pusz 4f30ecdefe style: pre-commit 2026-01-27 20:22:52 +01:00
Mateusz Pusz f097d96946 docs: large docs update (new tutorials, index pages) 2026-01-25 22:15:23 +01:00
Mateusz Pusz 61d396f714 docs: quantity hierarchies regenerated 2026-01-20 14:05:17 +01:00
Mateusz Pusz 4f14a92351 docs: quantity hierarchy handling improved 2026-01-20 13:57:17 +01:00
Mateusz Pusz f3efabfb0c docs: unreadable links in dark mode fixed for quantity hierarchies 2026-01-19 15:39:09 +01:00
Mateusz Pusz 55dece2226 docs: "Supported Systems Overview" chapter removed as not longer needed 2026-01-18 16:50:57 +01:00
Mateusz Pusz 1909d3d067 docs: broken links to some generated entities fixed 2026-01-18 16:44:46 +01:00
Mateusz Pusz be5e7881c5 style: pre-commit 2026-01-18 16:23:03 +01:00
Mateusz Pusz c4b8e0bdc9 docs: hyperlinks added to hierarchy trees 2026-01-18 14:40:45 +01:00
Mateusz Pusz f7ee6bf44e docs: improvements to systems generation script 2026-01-18 12:40:28 +01:00
Mateusz Pusz 170f4e4562 docs: hyperlinks added to system tables 2026-01-17 17:20:09 +01:00
Mateusz Pusz 35d766a8a5 docs: initial version of the systems documentation generator
Resolves #251
2026-01-16 18:00:09 +01:00
Mateusz Pusz 96fb061ff3 docs: systems overview table improved 2026-01-14 21:19:10 +01:00
Mateusz Pusz 3cdc01b108 docs: IAU and astronomy systems documentation added 2026-01-14 19:53:15 +01:00
Mateusz Pusz 92a8657dd1 docs: IEC 80000 renamed to IEC 2026-01-14 15:57:00 +01:00
Mateusz Pusz 8c95e4677f docs: "Yard-Pound Systems" chapter added 2026-01-14 14:39:06 +01:00
Mateusz Pusz afbe639772 docs: broken admonitions indentation fixed 2026-01-14 12:31:27 +01:00
Mateusz Pusz 9c5f2412bc refactor: 💥 international system renamed to yard_pound 2026-01-14 12:21:45 +01:00
Mateusz Pusz 23707ad11f docs: systems guide and reference improved 2026-01-14 11:46:50 +01:00
Mateusz Pusz 8ab5ef34fa docs: "Supported Systems Overview" chapter added 2026-01-14 10:41:25 +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 4b3e31f40d docs: initial V2 documenatation added 2023-06-21 10:55:18 +02:00
Tobias Lorenz 537aca2bc0 Add "inch of mercury" pressure unit as US Custom Unit
Signed-off-by: Tobias Lorenz <tobias.lorenz@gmx.net>
2023-05-25 07:35:57 +02:00
dbraeckelmann 39262fde5f Fixed typo in storage_capacity.rst headline 2023-05-09 10:31:16 +02:00
Mateusz Pusz abc429a71a refactor: rotation angle unit renamed to revolution 2022-09-05 12:12:12 +02:00
Mateusz Pusz f34282811d docs: angular quantities documentation improved 2022-09-03 12:28:21 +02:00
Mateusz Pusz 9aa3fd4d00 fix: prefixed_alias_unit constraints fixed 2022-08-03 11:29:20 +02:00
Mateusz Pusz 0f37d0af60 docs: Broken links in the documentation fixed 2022-08-02 18:36:17 +02:00