最小和最大运行值 [英] min and max running values

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

问题描述




我经常需要阅读数字,只保留最高或最低。

所以我做了类似的事情

int uLimit = 0;

int lLimit = 999999999999; //希望编译器不会抱怨


uLimit = val_read uLimit? val_read:uLimit;

lLimit = val_read< lLimit? val_read:lLimit;


如何选择原来的lLimit?

有更多的切割方式吗?


谢谢

Hi

often I need to read numbers and only keep the highest or lowest.
so I do something like
int uLimit = 0;
int lLimit = 999999999999; //hoping the compiler will not complain

uLimit = val_read uLimit ? val_read : uLimit;
lLimit = val_read < lLimit ? val_read : lLimit;

how do I choose the original lLimit?
is there more cleaver way?

thanks

推荐答案

Gary Wessle写道:
Gary Wessle wrote:



我经常需要阅读数字并且只保留最高或最低。

所以我做了类似

int uLimit = 0;
Hi

often I need to read numbers and only keep the highest or lowest.
so I do something like
int uLimit = 0;



''int''可以是负数,你知道......

''int'' can be negative, you know...


int lLimit = 999999999999 ; //希望编译器不会抱怨
int lLimit = 999999999999; //hoping the compiler will not complain



为什么不只是


int lLimit = INT_MAX; //或者使用std :: numeric_limits< int> :: max

Why not just

int lLimit = INT_MAX; // or use std::numeric_limits<int>::max

?


>

uLimit = val_read uLimit? val_read:uLimit;

lLimit = val_read< lLimit? val_read:lLimit;


如何选择原来的lLimit?

有更多的切割方法吗?
>
uLimit = val_read uLimit ? val_read : uLimit;
lLimit = val_read < lLimit ? val_read : lLimit;

how do I choose the original lLimit?
is there more cleaver way?



聪明?我不知道。可靠性更好。


V

-

请在通过电子邮件回复时删除资金'A'

我没有回复最热门的回复,请不要问

Clever? I don''t know. Reliable more like it.

V
-
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


On 2007-03-05 10:22:49 -0800,Gary Wessle< ph **** @ yahoo.comsaid:
On 2007-03-05 10:22:49 -0800, Gary Wessle <ph****@yahoo.comsaid:




我经常需要读取数字,只保留最高或最低。

所以我做了类似

int uLimit = 0;
Hi

often I need to read numbers and only keep the highest or lowest.
so I do something like
int uLimit = 0;



负值怎么样?

What about negative values?


int lLimit = 999999999999; //希望编译器不会抱怨
int lLimit = 999999999999; //hoping the compiler will not complain



为什么希望?为什么不直接获得正确的价值?

Why "hope"? Why not just get the value right to begin with?


>

uLimit = val_read uLimit? val_read:uLimit;

lLimit = val_read< lLimit? val_read:lLimit;


如何选择原来的lLimit?
>
uLimit = val_read uLimit ? val_read : uLimit;
lLimit = val_read < lLimit ? val_read : lLimit;

how do I choose the original lLimit?



#include< limits>

#include< algorithm>


.. ..


int uLimit = std :: numeric_limits< int> :: min();

int lLimit = std :: numeric_limits< int> :: max();


uLimit = std :: max(val_read,uLimit);

lLimit = std :: min(val_read,uLimit);

#include <limits>
#include <algorithm>

....

int uLimit = std::numeric_limits<int>::min();
int lLimit = std::numeric_limits<int>::max();

uLimit = std::max(val_read, uLimit);
lLimit = std::min(val_read, uLimit);


有更多的切割方式吗?


谢谢
is there more cleaver way?

thanks



- -

Clark S. Cox III
cl ******* @ gmail。 com


--
Clark S. Cox III
cl*******@gmail.com


如何选择原始lLimit?
how do I choose the original lLimit?

有更多的切割方式吗?
is there more cleaver way?



使用std :: numeric_limits< int> :: max()和

std :: numeric_limits< int> :: min() 。

use std::numeric_limits<int>::max() and
std::numeric_limits<int>::min().


这篇关于最小和最大运行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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