Avoid double rounding decimal literals when materializing f32 values
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Read the literal path through front/lexer/src/scan.rs:470, front/parser/src/expr/primary.rs:349, and front/hir/src/numeric_checks.rs:57 to see where decimal source information is lost before f32 materialization. Discuss the design with @LunaStev before implementation. Reproduce the given program at O0 and O2, then use exact-oracle tests for midpoints, adjacent decimals, negative values, and finite range boundaries; done means the reproduction yields 0x3f800001 while casts, spans, and diagnostics retain their stated semantics.
索引モデルが issue の本文から書いたものです。
説明
Problem
Decimal floating literals are first converted to f64 in the lexer, then narrowed when Typed HIR selects f32. Near an f32 halfway point, rounding to f64 first can erase which side of the midpoint the original decimal occupied, producing the wrong nearest f32 value.
Starting points: front/lexer/src/scan.rs:470, front/parser/src/expr/primary.rs:349, and front/hir/src/numeric_checks.rs:57. This differs from #927's accepted f32 default and normal finite rounding: the example is rounded to the wrong f32 neighbor even with an explicit f32 declaration.
Reproduction
Audited canonical master d59bdab376bdc04edacdc8029b256cb8d55b5adf on Linux amd64 with a checkout-built Wave 0.0.1-alpha-dev, Rust 1.89.0 and LLVM 21.1.8.
import("std::math::float")::{float_to_bits_f32};
fun main() {
var value: f32 = 1.0000000596046448;
println("{}", float_to_bits_f32(value));
}
At both O0 and O2 the native program prints 1065353216 (0x3f800000, exactly 1.0).
The exact midpoint between 1.0 and its next f32 neighbor is 1 + 2^-24 = 1.000000059604644775390625. The source decimal 1.0000000596046448 is strictly greater than that midpoint, so its nearest f32 is the next neighbor: bits 1065353217 / 0x3f800001.
The midpoint comparison was checked using Python Decimal with precision 80; it does not use another f64 conversion as the oracle.
Scope
Preserve sufficient source information until the selected floating materialization width is known, and round the literal to that width correctly. Keep f32 as the untyped default, contextual f64 behavior, explicit conversion order, signed zero, underflow and overflow diagnostics. Do not reinterpret this as a request to reject all inexact decimals.
Please mention @LunaStev to discuss the design before starting implementation.
This touches the frontend literal representation shared by both backends, so it is not labeled a good first issue.
Completion criteria
- The reproduction yields
0x3f800001at O0/O2. - Test exact midpoints, decimal values immediately on either side, negative values and finite range boundaries with an exact oracle.
- Preserve source spans and explicit f64-to-f32 cast semantics; distinguish directly materialized f32 literals from intentionally rounded cast chains.
- 主要言語
- Rust
- スター
- 56
- フォーク
- 21
- 平均マージ
- 23時間 20分
- マージ済み PR(30日)
- 45
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
wavefnd/Wave のほかの issue
-
Reject unrepresentable POSIX listener descriptors before Unix-domain accept対応中かも @ShahadatTest が 6 日前に担当しました。 オープンbug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
wavefnd/Wave#1082 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Preserve expression assembly result types when recording HIR conversions対応中かも @hiyouwhatsapp が 2 日前に担当しました。 オープンbug help wanted
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
bug help wanted
難易度 4/5 3〜5日 初心者へのやさしさ 53/100
メンテナーはふだん 1 日以内に返信
-
Preserve the previous build output when writing its Cargo receipt fails対応中かも @hiyouwhatsapp が 2 日前に担当しました。 オープンbug build help wanted
難易度 4/5 3〜5日 初心者へのやさしさ 56/100
メンテナーはふだん 1 日以内に返信
-
Reconcile obsolete staging assets before verifying a new Nightly generation対応中かも @hiyouwhatsapp が 2 日前に担当しました。 オープンbug ci help wanted
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
Panic on live viewport resize when unstyled elements exist in display: none subtree対応中かも @GoCoder7 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
DioxusLabs/blitz#1488 ·
メンテナーはふだん 1 日以内に返信
-
🏷️ good first issue enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
S-Needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
vectordotdev/vrl#2042 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信