0

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?

Community
  • 1
  • 1
Konstantin Isupov
  • 199
  • 1
  • 2
  • 12
  • 1
    Please edit your question and remove the pictures of text. Instead add the actual text. Also show your output and what output you expect. Right now it is unclear what exactly is the question. – drescherjm Nov 20 '16 at 15:04
  • I don't use MingGW, but I've used CMake and a Linux toolchain a bit. Maybe try changing your variable `GCC_COVERAGE_COMPILE_FLAGS` value to `-std=c++11` seeing that `` is a `C++11` feature ? – PrimRock Nov 20 '16 at 15:31
  • @PrimRock Unfortunately, it did not help. – Konstantin Isupov Nov 20 '16 at 17:30
  • In C++, use `#include ` and `std::` namespace prefix. – DaBler Nov 20 '16 at 17:32
  • Try what @DaBler said and use `#include ` and see what happens – PrimRock Nov 20 '16 at 18:49
  • @DaBler `#include ` and `std::` produced no result, since `MinGW\lib\gcc\mingw32\4.8.1\include\c++\cfenv` also has the condition `#if _GLIBCXX_USE_C99_FENV_TR1`. [See image](https://s16.postimg.org/ww41vm82d/image.png) – Konstantin Isupov Nov 20 '16 at 19:40
  • @KonstantinIsupov: Is the `_GLIBCXX_USE_C99_FENV_TR1` macro defined in your `bits/c++config.h` (look for it in the mingw32 directory)? – DaBler Nov 21 '16 at 20:02

0 Answers0