P3935R0 "Rebasing <cmath> on C23"
proposes pulling the remaining C23 <math.h> functions into C++, since C++26 is based on C23
but <cmath> is still based on C17. The paper puts decimal floating-point out of its own scope,
but nearly everything it lists is an ISO/IEC 60559 operation that
C23 Annex H already requires for
_Decimal32 / _Decimal64 / _Decimal128. Boost.Decimal should provide all of them regardless
of what C++29 adopts — the paper even notes that iscanonical and canonicalize are "primarily
motivated by ISO/IEC 60559 decimal floating-point representations."
This issue tracks that surface across all six types (decimal32_t, decimal64_t, decimal128_t,
decimal_fast32_t, decimal_fast64_t, decimal_fast128_t), plus the decimal-only functions from
C23 Annex H that P3935R0 does not cover.
Checked items are already provided; a trailing note gives our current spelling where it differs
from C23.
Classification and canonicalization
Comparison
NaN payload
Trigonometric (pi-scaled)
Exponential and logarithmic
Power
Rounding and integer conversion
The fromfp family takes a rounding direction from the FP_INT_* macros below and a bit width,
and returns NaN when the value is not representable.
Maximum and minimum
C23 replaced C99's fmax / fmin NaN behaviour with an IEEE 754-2019 conforming set. The library
currently provides only fmax and fmin.
Note that for decimal types these are not simply a comparison: when the operands compare equal but
belong to different cohorts, IEEE 754-2019 specifies which member of the cohort is returned.
Narrowing arithmetic
Narrowing arithmetic: compute in the wider format and round once to the narrower result format.
C23 spells the decimal versions d32addd64, d32addd128, d64addd128, and so on. P3935R0
proposes exposing them in C++ as function templates parameterised on the return type
(std::fadd<T>(x, y)) rather than by name suffix; see open questions.
Decimal-specific (C23 Annex H)
These have no binary counterpart and so are absent from P3935R0, but they belong in any complete
C23 decimal implementation.
Macros
P3935R0 "Rebasing
<cmath>on C23"proposes pulling the remaining C23
<math.h>functions into C++, since C++26 is based on C23but
<cmath>is still based on C17. The paper puts decimal floating-point out of its own scope,but nearly everything it lists is an ISO/IEC 60559 operation that
C23 Annex H already requires for
_Decimal32/_Decimal64/_Decimal128. Boost.Decimal should provide all of them regardlessof what C++29 adopts — the paper even notes that
iscanonicalandcanonicalizeare "primarilymotivated by ISO/IEC 60559 decimal floating-point representations."
This issue tracks that surface across all six types (
decimal32_t,decimal64_t,decimal128_t,decimal_fast32_t,decimal_fast64_t,decimal_fast128_t), plus the decimal-only functions fromC23 Annex H that P3935R0 does not cover.
Checked items are already provided; a trailing note gives our current spelling where it differs
from C23.
Classification and canonicalization
issignaling— provided, documented under "Non-standard Functions"iscanonical— C23 specifies exactly which decimal encodings are canonical, so unlike thebinary case this has a hard definition (non-canonical declets in DPD, significands above
the format maximum in BID)
issubnormaliszerocanonicalizeComparison
iseqsig—compareSignalingEqual; raisesFE_INVALIDon quiet NaN, unlikeoperator==totalorder— could alias the existingcomparetotal; see open questionstotalordermagNaN payload
getpayload— could alias the existingread_payloadsetpayloadsetpayloadsigTrigonometric (pi-scaled)
acospiasinpiatanpiatan2picospisinpitanpiExponential and logarithmic
exp10exp10m1exp2m1log10p1logp1— same value as the existinglog1p, different C23 spellinglog2p1Power
compoundn—(1 + x)^n;pown—x^nfor integralnpowr—e^(y * log(x)), defined only forx >= 0rootn—x^(1/n)rsqrt—1 / sqrt(x)Rounding and integer conversion
roundeven— nearest integer with halfway cases rounded to evenfromfpufromfpfromfpxufromfpxThe
fromfpfamily takes a rounding direction from theFP_INT_*macros below and a bit width,and returns NaN when the value is not representable.
Maximum and minimum
C23 replaced C99's
fmax/fminNaN behaviour with an IEEE 754-2019 conforming set. The librarycurrently provides only
fmaxandfmin.fmaximumfminimumfmaximum_numfminimum_numfmaximum_magfminimum_magfmaximum_mag_numfminimum_mag_numNote that for decimal types these are not simply a comparison: when the operands compare equal but
belong to different cohorts, IEEE 754-2019 specifies which member of the cohort is returned.
Narrowing arithmetic
faddfsubfmulfdivffmafsqrtNarrowing arithmetic: compute in the wider format and round once to the narrower result format.
C23 spells the decimal versions
d32addd64,d32addd128,d64addd128, and so on. P3935R0proposes exposing them in C++ as function templates parameterised on the return type
(
std::fadd<T>(x, y)) rather than by name suffix; see open questions.Decimal-specific (C23 Annex H)
These have no binary counterpart and so are absent from P3935R0, but they belong in any complete
C23 decimal implementation.
quantize— provided asquantizesamequantum— provided assamequantumquantexp— provided asquantexpencodedec/decodedec— provided asto_dpd/from_dpdencodebin/decodebin— provided asto_bid/from_bidquantum— returns the quantum of a finite value as a value of the same typellquantexp—quantexpreturninglong longMacros
FP_INT_UPWARDFP_INT_DOWNWARDFP_INT_TOWARDZEROFP_INT_TONEARESTFROMZEROFP_INT_TONEARESTFP_FAST_*narrowing-arithmetic hints — C23 spells the decimal analoguesFP_FAST_D32ADDD64,FP_FAST_D32ADDD128,FP_FAST_D64ADDD128, and correspondingly forSUB/MUL/DIV/FMA/SQRT