Constexpr数学函数 [英] Constexpr Math Functions

查看:263
本文介绍了Constexpr数学函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,从这个网页中注意到,c ++ 11中的数学函数似乎没有使用constexpr,而我相信所有的都可以。这让我有两个问题,一个是为什么他们选择不使用constexpr的函数。对于像 sqrt 这样的函数的两个可能写我自己的constexpr,但是类似sin或cos的东西会更棘手,所以它周围有。

So noticed from this page that none of the math functions in c++11 seems to make use of constexpr, whereas I believe all of them could be. So that leaves me with two questions, one is why did they choose not to make the functions constexpr. An two for a function like sqrt I could probably write my own constexpr, but something like sin or cos would be trickier so is there away around it.

推荐答案

实际上,由于旧的和讨厌的遗产,几乎没有一个数学函数可以 constexpr ,因为它们都有在各种错误条件(通常是域错误)上设置 errno 的副作用。

Actually, because of old and annoying legacy, almost none of the math functions can be constexpr, since they all have the side-effect of setting errno on various error conditions, usually domain errors.

这篇关于Constexpr数学函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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