我想按this topic和cppreference中的建议使用标准库更改浮点舍入模式。我使用MingGW作为环境。 CMake用于构建项目。我的代码:
main.cpp中:
#include <stdio.h>
#include <math.h>
#include <fenv.h>
#pragma STDC FENV_ACCESS ON
void show_fe_current_rounding_method(void)
{
printf("current rounding method: ");
switch (fegetround()) {
case FE_TONEAREST: printf ("FE_TONEAREST"); break;
case FE_DOWNWARD: printf ("FE_DOWNWARD"); break;
case FE_UPWARD: printf ("FE_UPWARD"); break;
case FE_TOWARDZERO: printf ("FE_TOWARDZERO"); break;
default: printf ("unknown");
};
printf("\n");
}
的CMakeLists.txt:
cmake_minimum_required(VERSION 3.6)
project(test)
SET(GCC_COVERAGE_COMPILE_FLAGS "-std=c++11 -march=native -mavx")
SET(CMAKE_CXX_FLAGS "${GCC_COVERAGE_COMPILE_FLAGS}")
但是,编译期间会出现以下错误:
error: 'fegetround' was not declared in this scope...
error: 'FE_TONEAREST' was not declared in this scope..
error: 'FE_DOWNWARD' was not declared in this scope...
error: 'FE_UPWARD' was not declared in this scope...
error: 'FE_TOWARDZERO' was not declared in this scope...
这就是<fenv.h>
的内容在我的代码中不可用(#if _GLIBCXX_USE_C99_FENV_TR1
中的条件\MinGW\lib\gcc\mingw32\4.8.1\include\c++\fenv.h
不满足)。我做错了什么?