Error in square root for cpp_dec_float_100

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp
領域
backend

調査の方向性

提供された再現コードと、boost/multiprecision/cpp_dec_float.hpp によって公開されている sqrt の経路から始め、Boost 1.71.0 および 1.79.0/1.80.0 と動作を比較します。sqrt(49) がゼロでない最終桁を生成する理由を追跡します。再現コードが 7 と等しく比較され、期待される値を出力すれば完了です。

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

説明

I recently updated boost from 1.71.0 to 1.80.0 and I started getting an error. After some investigation the problem arises from an incorrect rounding on the square root of 49 that makes it 7.000...01 instead of just 7. Here's the code that shows the issue

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <iostream>

using boost::multiprecision::cpp_dec_float_100;
using std::string;

int main() {
    cpp_dec_float_100 n(49);
    n = sqrt(n);
    if (n == (uint32_t) n)
        std::cout << "This should be logged as sqrt(49) = 7" << std::endl;
    else
        std::cout << "Error: sqrt(49) != 7" << std::endl;

    std::cout << std::endl << n.str() << std::endl;
    
    return 0;
}
Error: sqrt(49) != 7

7.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001

I also replicated the issue here with version 1.79.0. In version 1.71.0 the calculation was correct.

主要言語
C++
スター
268
フォーク
130
平均マージ
1日 15時間
マージ済み PR(30日)
2

環境構築

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

はじめの一歩

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

boostorg/multiprecision のほかの issue

boostorg/multiprecision の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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