Commit Graph

338 Commits

Author SHA1 Message Date
Mateusz Pusz c3d5fc6dbb docs: non_negative declarations added to quantity_spec in docs
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 21:10:01 +02:00
Mateusz Pusz 810c5a9c41 docs: quantity point bounds documentation updated
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 10:49:24 +02:00
Mateusz Pusz 7b2603a8ba docs: safe_int documentation improved 2026-04-27 23:28:12 +02:00
Mateusz Pusz 9b1734e319 docs: "Representation Types" chapter contents restored
Co-authored-by: Copilot <copilot@github.com>
2026-04-27 14:37:47 +02:00
Mateusz Pusz 659738044a feat: safe_int implicit conversions improved and refactored the operators + widening for scaling now preserves sign
Co-authored-by: Copilot <copilot@github.com>
2026-04-26 16:03:09 +02:00
Mateusz Pusz e3f8cc0dc4 docs: "Representation types" updated with the latest changes 2026-04-25 21:04:40 +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 b9d801dc34 docs: representation types docs improved
Co-authored-by: Copilot <copilot@github.com>
2026-04-25 19:16:22 +02:00
Mateusz Pusz 08e1645dfe feat: UsesIntegerScaling now properly requires multiplication by a wider type 2026-04-25 12:52:05 +02:00
Mateusz Pusz 6263e2b8c5 feat: representation_underlying_type provided instead of indirectly_readable_traits usage 2026-04-21 22:10:19 +02:00
Mateusz Pusz 1fbb410549 docs: safe_int overflow example simplified 2026-04-12 11:12:45 +02:00
Mateusz Pusz dca1ccfc80 docs: HEP system description improved 2026-04-11 22:15:55 +02:00
Mateusz Pusz 12300bcd23 feat: safe_int and blog article about it added 2026-04-11 20:30:28 +02:00
Mateusz Pusz e2e490f0cd refactor: scaling algorithm and concepts simplified 2026-04-11 19:00:33 +02:00
Mateusz Pusz 2eb094c0b1 feat: scaling widening changed to always use std::int64_t for smaller types 2026-04-08 17:56:26 +02:00
Mateusz Pusz a1e1e7cb21 feat: non-negative quantities support added
Resolves #468
2026-04-06 22:51:42 +02:00
Mateusz Pusz a89b93bab2 feat: 💥 Celsius_temperature removed from ISQ 2026-04-04 09:11:33 +02:00
Mateusz Pusz 459211fc7a feat: quantity point bounds design finalized 2026-04-03 23:38:47 +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 500046873b feat: two more overflow policies added 2026-03-31 13:52:20 +02:00
Mateusz Pusz e6667e3444 style: pre-commit 2026-03-31 11:40:11 +02:00
Mateusz Pusz 8cde16d7a4 docs: affine space SVG graphs styles improved to be visible in dark mode 2026-03-30 21:40:00 +02:00
Mateusz Pusz 16056181ce feat: range checking for points added 2026-03-30 21:39:06 +02:00
Mateusz Pusz a13e7db324 docs: broken link fixed 2026-03-24 05:54:33 +00:00
Mateusz Pusz d8b72fc431 refactor: scaling the value by magnitude heavily refactored 2026-03-19 00:28:15 +01:00
Mateusz Pusz cb673be844 docs: "Quantity specification" in "Design overview" description fixed 2026-03-13 09:03:14 +01:00
Mateusz Pusz 37288e9c4f style: pre-commit 2026-03-11 23:40:16 +01:00
Mateusz Pusz 3484e9ed83 docs: RepresentationOf concept description improved 2026-03-11 22:32:09 +01:00
Mateusz Pusz 6cfd1540b4 docs: "Design overview" chapter updated 2026-03-11 22:14:58 +01:00
Mateusz Pusz 3f2f09fd77 docs: representation type-related docs updated 2026-03-11 22:14:15 +01: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 a62eac3f69 docs: "Header Files chapter added to the SI User's Guide 2026-02-25 20:52:22 +01:00
Mateusz Pusz 7918cb2072 docs: CERN Software links updated 2026-02-25 15:53:15 +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 e2c86d0804 docs: references to CERN and ATLAS experiment removed from the HEP system page 2026-02-25 14:06:45 +01:00
Mateusz Pusz c1c52986bf style: pre-commit 2026-02-25 13:47:58 +01:00
Mateusz Pusz 6967e25557 docs: the quote in "The Problem" chapter refactored by the request of the author 2026-02-25 13:36:04 +01:00
Mateusz Pusz cb875ea717 docs: HEP System description in User's Guide simplified 2026-02-25 11:43:08 +01:00
Mateusz Pusz aa2a0020cb feat: all constants now use named_constant 2026-02-23 17:35:30 +01:00
Mateusz Pusz 6f3ef66d4b feat: comparisons against literal 0
Resolves #487
2026-02-23 11:07:22 +01:00
Mateusz Pusz 7693360b21 docs: "Type Safety in Practice" chapter updated 2026-02-22 01:16:26 +01:00
Mateusz Pusz 6ff427af72 docs: minor improvements 2026-02-22 01:03:31 +01:00
Mateusz Pusz ce1769ff4b docs: HEP system description updated 2026-02-22 00:57:25 +01:00
Mateusz Pusz 28796f8d42 docs: HEP system description updated 2026-02-21 23:56:20 +01:00
Mateusz Pusz bb465b323a docs: initial version of HEP system description added 2026-02-21 21:40:32 +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 7d466648e3 docs: workshops numbers removed and split to subdirectories 2026-01-25 23:48:29 +01:00
Mateusz Pusz 6703f3e835 docs: Hwo-to Guides directory structure refactored 2026-01-25 22:58:22 +01:00
Mateusz Pusz f097d96946 docs: large docs update (new tutorials, index pages) 2026-01-25 22:15:23 +01:00
Mateusz Pusz 5a7ab1f42d docs: strongly-typed numeric types chapter added to dimensionless quantities 2026-01-21 23:38:02 +01:00