ceil, floor, round を使ってみる (C++)
C++
Published: 2019-12-08

やったこと

下記の関数を使ってみます。

  • ceil
  • floor
  • round

確認環境

$ g++ --version
g++ (Homebrew GCC 9.2.0) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

調査

test.cpp

#include <bits/stdc++.h>
using namespace std;

int main() {
    cout << "ceil" << endl;
    cout << ceil(5.4) << endl;
    cout << ceil(5.9) << endl;

    cout << "floor" << endl;
    cout << floor(5.4) << endl;
    cout << floor(5.9) << endl;

    cout << "round" << endl;
    cout << round(5.4) << endl;
    cout << round(5.9) << endl;
}

出力結果

ceil
6
6
floor
5
5
round
5
6

参考