fenv_access pragma的范围是什么 [英] What is the scope of the fenv_access pragma

查看:184
本文介绍了fenv_access pragma的范围是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


根据  cplusplus.com   FENV_ACCESS宏可以在复合语句中使用并恢复。


https://msdn.microsoft.com/en-us/library/bfwa91s0.aspx 目前还不清楚fenc access pragma的范围(与宏不同)。此外,它似乎只与2012年,2013年和2015年相关。


任何人都可以澄清什么是可能的。 我的目标是在编写区间运算时在尽可能小的范围内使用fenv_access。



解决方案

嗯,编译器很乐意告诉你。


1> main.cpp(21):警告C4177:#pragma'fenv_access'应仅用于全局范围或命名空间范围


但是有明显的限制范围的方法:

 #include< stdio.h> 
#include< float.h>
#include< errno.h>

#pragma fenv_access(on)
inline void calc1(double b,double t)
{
double z = b * t;
printf_s(" out =%。15e \ n",z);
}
#pragma fenv_access(off)

inline void calc2(double b,double t)
{
double z = b * t;
printf_s(" out =%。15e \ n",z);
}

int main(){
double z,b = 0.1,t = 0.1;
unsigned int currentControl;
errno_t错误;

err = _controlfp_s(& currentControl,_PC_24,_MCW_PC);
if(err!= 0){
printf_s(" the function _controlfp_s failed!\ n");
返回-1;
}

calc1(b,t);
calc2(b,t);
}

将要应用fenv_access的功能放入其自己的函数并调用它,然后让编译器内联它。


Hello,

According to cplusplus.com  the FENV_ACCESS macro can be used inside a compound statement and is restored.

https://msdn.microsoft.com/en-us/library/bfwa91s0.aspx   is not clear about the scope of the fenc access pragma (not identical to the macro). Also it seems only relevant for VC 2012, 2013, and 2015.

Can anybody clarify what is possible.  My goal is to use fenv_access at the smallest possible scope when writing interval arithmetic.

解决方案

Well, the compiler will happily tell you.

1>main.cpp(21): warning C4177: #pragma 'fenv_access' should only be used at global scope or namespace scope

But there is the obvious ways of limiting the scope of this:

#include <stdio.h>
#include <float.h>
#include <errno.h>

#pragma fenv_access (on)
inline void calc1(double b, double t)
{
	double z = b * t;
	printf_s("out=%.15e\n", z);
}
#pragma fenv_access (off)

inline void calc2(double b, double t)
{
	double z = b * t;
	printf_s("out=%.15e\n", z);
}

int main() {
	double z, b = 0.1, t = 0.1;
	unsigned int currentControl;
	errno_t err;

	err = _controlfp_s(&currentControl, _PC_24, _MCW_PC);
	if (err != 0) {
		printf_s("The function _controlfp_s failed!\n");
		return -1;
	}

	calc1(b, t);
	calc2(b, t);
}

putting the functionality that you want to apply the fenv_access into its own function and call that, then let the compiler inline it.


这篇关于fenv_access pragma的范围是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆