When you use abs, don't forget to write include cmath #include <cmath> これを付けずにstd::absを(doubleに対して)使うとコンパイルエラーになったりならなかったりする。