C23 <math.h> Functions

オープン
#1,429 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
cpp
領域
tooling

調査の方向性

リンクされている論文 P3935R0 と C23 Annex H から始め、checked と unchecked の API サーフェスを、comparetotal、read_payload、log1p、quantize、DPD/BID 変換ヘルパーなどの既存の名前と比較します。6 つすべての decimal 型について未解決の API の問題を解決し、選択した関数とマクロを実装し、指定された C23 および IEEE 754 の動作を実証するカバレッジを追加します。

索引モデルが issue の本文から書いたものです。

説明

enhancement

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

  • issignaling — provided, documented under "Non-standard Functions"
  • iscanonical — C23 specifies exactly which decimal encodings are canonical, so unlike the
    binary case this has a hard definition (non-canonical declets in DPD, significands above
    the format maximum in BID)
  • issubnormal
  • iszero
  • canonicalize

Comparison

  • iseqsig — compareSignalingEqual; raises FE_INVALID on quiet NaN, unlike operator==
  • totalorder — could alias the existing comparetotal; see open questions
  • totalordermag

NaN payload

  • getpayload — could alias the existing read_payload
  • setpayload
  • setpayloadsig

Trigonometric (pi-scaled)

  • acospi
  • asinpi
  • atanpi
  • atan2pi
  • cospi
  • sinpi
  • tanpi

Exponential and logarithmic

  • exp10
  • exp10m1
  • exp2m1
  • log10p1
  • logp1 — same value as the existing log1p, different C23 spelling
  • log2p1

Power

  • compoundn — (1 + x)^n;
  • pown — x^n for integral n
  • powr — e^(y * log(x)), defined only for x >= 0
  • rootn — x^(1/n)
  • rsqrt — 1 / sqrt(x)

Rounding and integer conversion

  • roundeven — nearest integer with halfway cases rounded to even
  • fromfp
  • ufromfp
  • fromfpx
  • ufromfpx

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.

  • fmaximum
  • fminimum
  • fmaximum_num
  • fminimum_num
  • fmaximum_mag
  • fminimum_mag
  • fmaximum_mag_num
  • fminimum_mag_num

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

  • fadd
  • fsub
  • fmul
  • fdiv
  • ffma
  • fsqrt

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.

  • quantize — provided as quantize
  • samequantum — provided as samequantum
  • quantexp — provided as quantexp
  • encodedec / decodedec — provided as to_dpd / from_dpd
  • encodebin / decodebin — provided as to_bid / from_bid
  • quantum — returns the quantum of a finite value as a value of the same type
  • llquantexp — quantexp returning long long

Macros

  • FP_INT_UPWARD
  • FP_INT_DOWNWARD
  • FP_INT_TOWARDZERO
  • FP_INT_TONEARESTFROMZERO
  • FP_INT_TONEAREST
  • FP_FAST_* narrowing-arithmetic hints — C23 spells the decimal analogues
    FP_FAST_D32ADDD64, FP_FAST_D32ADDD128, FP_FAST_D64ADDD128, and correspondingly for
    SUB / MUL / DIV / FMA / SQRT
主要言語
C++
スター
67
フォーク
16
平均マージ
1日 15時間
マージ済み PR(30日)
12

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

boostorg/decimal のほかの issue

boostorg/decimal の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。