I want to change a floating-point rounding mode using standard library as suggested in this topic and cppreference. I use MingGW as an envirement. CMake is used to build of the project. My code:
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}")
However, the following errors are occur during the compilation:
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...
That is the content of <fenv.h>
is not available in my code (the condition #if _GLIBCXX_USE_C99_FENV_TR1
in \MinGW\lib\gcc\mingw32\4.8.1\include\c++\fenv.h
does not satisfied). What am I doing wrong?