Hexfloat ('a'/'A') zero padding is placed before the sign and "0x" prefix

クローズ 初心者向け
#4,971 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp
領域
backend

調査の方向性

hexfloat のパスは include/fmt/format.h の float の write() にあります。'a'/'A' プレゼンテーションを処理する分岐を見つけ、align::right で write_bytes を介して出力する前に、sign、'0x'、数字をどのように組み立てているかを確認してください。プレフィックスの後にすでにパディングを挿入している整数の16進パス("{:#012x}")と比較してください。3つの例と fmt::sprintf で再現し、その後、既存の format テストを実行してください。出力が printf と std::format に一致し、任意の符号の後にゼロが続き、"0x" プレフィックスが付いていれば完了です。

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

説明

With the 'a'/'A' presentation and the '0' flag, {fmt} puts the zero padding before the sign and the "0x" prefix:

fmt::format("{:012a}", 1.0) -> 0000000x1p+0
fmt::format("{:+012a}", 1.5) -> +0000x1.8p+0
fmt::format("{:012a}", -1.5) -> -0000x1.8p+0
printf("%012a", 1.0) -> 0x0000001p+0

Expected: 0x0000001p+0, +0x0001.8p+0, -0x0001.8p+0. C11 7.21.6.1 para 6 says leading zeros follow any sign or base indication, and std::format does the same. The integer path already does this right: fmt::format("{:#012x}", 0x1abc) gives 0x0000001abc. fmt::sprintf("%012a", ...) is affected too.

It looks like the hexfloat branch of the float write() in format.h builds sign + "0x" + digits and emits it with write_bytes at forced align::right, so the fill lands in front of the whole string.

fmt main @ 174569c, g++ 11.4.

I used AI tools to find and reproduce this; I reviewed it myself.

主要言語
C++
スター
25.9k
フォーク
3.1k
平均マージ
9日 5時間
マージ済み PR(30日)
13

環境構築

はじめの一歩

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

fmtlib/fmt のほかの issue

fmtlib/fmt の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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