Math.Round(x) rounds imprecisely under Fable 5.26.0
メンテナーはふだん 1 日以内に返信
関連するプルリクエストがすでにマージされています。
- #5254 @MangelMaxime による — マージ済み
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 62/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript
- 領域
- compilers
調査の方向性
The bug is in the round helper of fable-library-js (Util.round), which uses toFixed(8) and an epsilon tie check; the reproduction is the Math.Round loop over 2.500000001 and 3.4999999999 in the issue. Start by reading that helper and checking whether the same logic is mirrored in other Fable targets. Done when both values round to 3 and Math.Round(x, digits) matches .NET behaviour, with a regression test added.
索引モデルが issue の本文から書いたものです。
説明
Math.Round(double) calls a value a tie when its fraction is within 1e-8 of 0.5, so values near a half round the wrong way. That way 2.500000001 rounds down to 2 and 3.4999999999 rounds up to 4 under Fable 5.26.0, instead of 3 for both cases.
To reproduce this issue
open System
for x in [ 2.500000001; 3.4999999999 ] do
printfn "%s" (string (Math.Round x))
fable-library-js’s Util.round reads the value through toFixed(8) and calls it a tie when the fraction is within 1e-8 of 0.5
const n = +(digits ? value * m : value).toFixed(8);
...
const r = (f > 0.5 - e && f < 0.5 + e) ? ((i % 2 === 0) ? i : i + 1) : Math.round(n);
Math.Round(double) works on the exact value and a tie is a fraction of exactly one half.
Suggested fix that would be exact.
const t = Math.trunc(x), f = Math.abs(x - t);
return f > 0.5 ? t + Math.sign(x) : f < 0.5 ? t : (t % 2 === 0 ? t : t + Math.sign(x));
For Math.Round(x, digits) the same applies after scaling by 10^digits, as .NET does.
- 主要言語
- F#
- スター
- 3.2k
- フォーク
- 335
- 平均マージ
- 19時間 39分
- マージ済み PR(30日)
- 158
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
fable-compiler/Fable のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
fable-compiler/Fable#5280 ·
メンテナーはふだん 1 日以内に返信
-
agentic-workflows automation repo-assist
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
fable-compiler/Fable#4531 ·
メンテナーはふだん 1 日以内に返信
-
agentic-workflows automation repo-assist
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
fable-compiler/Fable#4522 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
fable-compiler/Fable#5286 ·
メンテナーはふだん 1 日以内に返信
-
for loop bound still differs from .NET for reassigned mutable arrays対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 36/100
fable-compiler/Fable#5285 ·
メンテナーはふだん 1 日以内に返信
fable-compiler/Fable の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
rubys/roundhouse#1950 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
tree-sitter/tree-sitter-cpp#381 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
new issue
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
llvm/llvm-project#240065 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 2 日以内に返信