Commit Graph

82 Commits

Author SHA1 Message Date
Mateusz Pusz 1c54623024 feat: import std; enabled for g++ 2026-06-03 21:29:55 +02:00
Mateusz Pusz ff2cb6c516 fix(test): Unicode characters removed from runtime test descriptions 2026-05-25 21:37:59 +02:00
Mateusz Pusz 8f4a13f50f fix: silence MSVC Debug C4702 by giving if constexpr chains an explicit else
MSVC's Debug code generator does not dead-code-eliminate after an `if constexpr`
chain whose branches all return, so the fallthrough `return` after the chain is
flagged C4702 (unreachable) on instantiations where one of the branches is
selected.  Release builds optimize the dead path out and never complain.

Restructure two places so the fallback lives inside an explicit `else` /
returning helper instead of a fallthrough:

  * `enforce_bounds()` (quantity_point.h): wrap the `return q;` fallback in
    `else { return q; }` after the existing `if constexpr` chain.
  * `compare_quantities()` (quantity.h): hoist the floating-point / already-widest
    fallback into a local `fallback_cmp` lambda invoked from both arms of the
    `if constexpr` chain.  Keeps the existing float-equal suppression.

For `CHECK_THROWS_AS` in constrained_test.cpp, Catch2's macro expands into a
try/catch whose catch arm becomes unreachable when the body calls a `[[noreturn]]`
function; suppress C4702 around that one TEST_CASE since the macro is not ours
to restructure.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-24 21:52:39 +02:00
Mateusz Pusz 1ee12968fe fix: wide_product_of is a dead code on platforms with __int128 + missing header for fixed_point_test.cpp 2026-05-24 20:09:58 +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 2690296059 feat: quantity_point text output added for default_point_origin 2026-05-21 18:38:09 +02:00
Mateusz Pusz 7c5769d549 test: check_non_negative propagates through relative_point_origin 2026-05-06 22:28:32 +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 76a7692180 test: constrained runtime unit tests refactored to SECTIONS 2026-04-11 20:32:39 +02:00
Mateusz Pusz 12300bcd23 feat: safe_int and blog article about it added 2026-04-11 20:30:28 +02:00
Mateusz Pusz 459211fc7a feat: quantity point bounds design finalized 2026-04-03 23:38:47 +02:00
Mateusz Pusz 500046873b feat: two more overflow policies added 2026-03-31 13:52:20 +02:00
Mateusz Pusz 6d555b73bd feat: norm() added to a cartesian_vector 2026-03-11 22:25:08 +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 9a374a5646 refactor: isq::time swapped with isq::duration 2026-01-09 09:22:37 +01:00
Mateusz Pusz 6d10a154fa feat: 💥 pi and π is now a unit constant (pi magnitude constant renamed to pi_c) 2025-12-28 13:35:54 +01:00
Roth Michaels 507b2dbd0d fix: enable runtime usage of inverse function by using compile-time unit extraction
Replace runtime unit access (q.unit) with compile-time type extraction
(get_unit(R)) in the inverse function implementation. This prevents the
function from becoming an immediate function when consteval unit operators
are used, allowing inverse to work with runtime variables.

Key changes:
- math.h: Use get_unit(R) instead of q.unit in both code paths
- test: Add comprehensive runtime inverse tests

This surgical fix preserves maximum compile-time optimization while
enabling DSP applications that need runtime inverse calculations.

Fixes compilation error with Clang:
"call to immediate function 'inverse' is not a constant expression"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-11 09:07:08 +00:00
Mateusz Pusz 2a2a53d5e8 build: projectPrefix CMake variable removed 2025-11-02 15:08:20 -08:00
Mateusz Pusz 37dfa39dba build: wg21-linear_algebra dependency removed 2025-07-11 16:59:13 +02:00
Mateusz Pusz 35798a0f39 refactor: ostream.h header file made deprecated 2025-06-20 10:40:10 +02:00
Mateusz Pusz 50c05bddb3 refactor: format.h header file made deprecated 2025-06-20 09:06:49 +02:00
Mateusz Pusz 5a0e350be7 feat: lerp and midpoint for points added 2025-02-13 14:26:51 +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 88439828a5 feat: std::numeric_limits support added
Resolves #408
2025-02-05 18:04:43 +01:00
Mateusz Pusz 0b14d69539 feat: quantity::one() removed
Related to #408
2025-02-05 12:08:32 +01:00
Mateusz Pusz 465f88d500 refactor: 💥 is_XXX customization points for representation types removed 2024-11-26 14:48:08 +01:00
Mateusz Pusz 0c09008671 fix: clang is too stupid to provide a deprecation warning for text_encoding 2024-11-21 11:25:57 +01:00
Mateusz Pusz 2cf64f20c5 fix: cartesian_vector convertibility tests fixed 2024-11-14 20:40:08 +01:00
Mateusz Pusz a7cf015a3e feat: add compound assignment operators to cartesian_vector 2024-11-14 20:38:50 +01:00
Mateusz Pusz 4b5d37e83e feat: constructors of cartesian_vector refactored 2024-11-14 20:30:12 +01:00
Mateusz Pusz 420ffef6c5 fix(test): missing header files added 2024-11-12 18:12:36 +01:00
Mateusz Pusz 73ad1f08d4 fix: fmt_test fixed to use delta to create a quantity of thermodynamic_temperature 2024-11-12 16:20:51 +01:00
Mateusz Pusz 5a206c3ef1 test: cartesian_vector used in fmt_test 2024-11-12 14:38:51 +01:00
Mateusz Pusz 6c3c1fe5f7 feat: cartesian_vector added 2024-11-12 14:34:18 +01:00
Mateusz Pusz d8574022f1 test: _surface tension_ replaced with _entropy_ in an fmt test 2024-11-12 14:21:36 +01:00
Mateusz Pusz c6344c26ee style: missing empty line at the end of the file added 2024-11-12 11:31:26 +01:00
Mateusz Pusz 78204c7e5f test: runtime unit tests refactored to have a bigger granularity (less top level tests) 2024-11-12 11:27:52 +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 af18a6ba51 refactor: 💥 𝜋 replaced with π 2024-10-24 07:22:45 +02:00
Mateusz Pusz 6591a65d06 feat: 𝜋 added as an alias for pi 2024-10-14 22:49:58 +02:00
Mateusz Pusz 527c6dae63 test: fmt unit tests updated to the latest version 2024-10-10 09:00:31 +02:00
Mateusz Pusz 4eb63227e2 refactor: 💥 ascii -> portable, unicode -> utf8, 'A' -> 'P' 2024-10-10 00:02:08 +02:00
Mateusz Pusz 51dc1d7469 fix: according to ISO 80000-16 % should always be prefixed with space 2024-10-03 11:54:40 +02:00
Mateusz Pusz 3671f64153 refactor: 💥 magnitudes code cleanup + mag_pi is now mag<pi> 2024-09-23 13:42:39 +02:00
Yves Delley 3e502fb795 increase tolerance for certain math tests to two epsilon 2024-09-16 20:34:12 +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 45013f6752 fix: inline restored for non-template constexpr global variables 2024-09-05 10:06:43 +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 f088d544b3 Fix known errors 2024-07-29 20:43:06 -04:00
Chip Hogg 3a6fac9858 Move tests to runtime 2024-07-24 20:04:15 -04:00