Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`fmod` of `interval<long double>` can miss the true result

オープン 初心者向け
#67 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

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

調査の方向性

detail/c99sub_rounding_control.hpp、detail/ppc_rounding_control.hpp、detail/sparc_rounding_control.hppを読み、それらのto_int実装を、issueで言及されているAlphaおよびIA-64バックエンドと比較してください。interval<long double>を使ってfmodの例を再現し、変更後に結果が0を含むことを確認してください。

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

説明

rounding_control<long double>::to_int calls rint, the double function, in three backends:

  • detail/c99sub_rounding_control.hpp, - Its extern "C" { double rint(double); } is declared inside namespace detail, so the template to_int<T> always finds that one.
  • detail/ppc_rounding_control.hpp
  • detail/sparc_rounding_control.hpp

A long double with more than 53 significant bits is rounded to double before it is rounded to an integer. int_down and int_up then return wrong values, sometimes on the wrong side of the argument, and fmod, which uses int_down, returns an interval that does not contain the true result:

#include <boost/numeric/interval.hpp>
#include <iostream>

int main() {
  typedef boost::numeric::interval<long double> I;
  I r = fmod(I(1152921504606846977.0L), I(1));  // 2^60 + 1
  std::cout << r.lower() << ' ' << r.upper() << '\n';  // must contain 0
}

It print 1 1 : godbolt

Step Expected Actual
x 2^60 + 1 = 1152921504606846977, exact in long double (64-bit significand) same
div_down(x, 1) 1152921504606846977 (exact) same
to_int of that rintl(1152921504606846977) = 1152921504606846977 rint(double(1152921504606846977)): converting to double (53 bits) gives 1152921504606846976 =
2^60
n = int_down(...) 2^60 + 1 2^60
x - n * 1 1152921504606846977 − 1152921504606846977 = 0 1152921504606846977 − 1152921504606846976 = 1
result z [0, 0] [1, 1]

The Alpha and IA-64 backends already declare rintl and use it in to_int(long double); doing the same in these three fixes it.

主要言語
C++
スター
31
フォーク
49
平均マージ
1日 4時間
マージ済み PR(30日)
9

環境構築

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

はじめの一歩

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

boostorg/interval のほかの issue

boostorg/interval の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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