0

我想按照本主题cppreference中的建议使用标准库更改浮点舍入模式。我使用 MingGW 作为环境。CMake 用于构建项目。我的代码:

主.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不满足条件)。我究竟做错了什么?

4

0 回答 0