至少三个值 [英] TAking the minimum of three values
问题描述
我需要找到至少三个浮点值。这样做最有效的方法是什么?有人可以和我分享#define宏或
这样做吗?谢谢
Sona
" Sona" ; <所以********** @ nospam.com>在留言中写道
新闻:3f ******** @ clarion.carno.net.au ...我需要找到至少三个浮点数价值..最有效的方法是什么?有人可以和我分享#define宏或
这样做吗?谢谢
Sona
x = min(a,min(b,c));
-Howard
Sona写道:我需要找到至少三个浮点值..什么这将是最有效的方式吗?有人可以和我分享#define宏或
这样做吗?谢谢
在C ++中
#include< algoritm>
double min3(双a,双b,双c){
返回std :: min(a,std :: min(b,c));
}
> #include< algoritm>
double min3(double a,double b,double c){
return std :: min(a,std :: min(b, c));
}
为了保持min的模板化方面,你甚至可以写出
命名空间
{
模板< class T>
T& min(T const& a,T const& b,T const& c)
{
return min(a,min(b,c));
}
}
就像std :: min适用于任何类型,并且有2或3个参数
I need to find a minimum of three float values.. what would be the most
efficient way of doing this? Can someone please share a #define macro or
something with me for doing this? Thanks
Sona
"Sona" <so**********@nospam.com> wrote in message
news:3f********@clarion.carno.net.au...I need to find a minimum of three float values.. what would be the most
efficient way of doing this? Can someone please share a #define macro or
something with me for doing this? Thanks
Sona
x = min( a, min( b, c ) );
-Howard
Sona wrote:I need to find a minimum of three float values.. what would be the most
efficient way of doing this? Can someone please share a #define macro or
something with me for doing this? Thanks
In C++
#include <algoritm>
double min3(double a, double b, double c) {
return std::min(a, std::min(b, c));
}
> #include <algoritm>
double min3(double a, double b, double c) {
return std::min(a, std::min(b, c));
}
To keep the templated aspect of min, you could even write
namespace
{
template<class T>
T& min(T const& a, T const& b, T const& c)
{
return min(a, min(b,c));
}
}
Like that std::min works with any type, and with 2 or 3 arguments
这篇关于至少三个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!