c++中如何返回内置类型的最值——使用
来源:互联网 发布:centos 移除openjdk 编辑:程序博客网 时间:2024/06/02 16:43
在c++的<limits>中定义了如下的一个模板类:
template<class Type> class numeric_limits
它可以求出下列内置类型的一些特性:
wchar_t, bool, char, signed char, unsigned char, short, unsigned short,
int, unsigned int, long, unsigned long, float, double, and long double.
有这么四个函数,比较有用:
max() Returns the maximum finite value for a type.
min() Returns the minimum normalized value for a type.
digits() Returns the number of radix digits that the type can represent without loss of precision.
digits10() Returns the number of decimal digits that the type can represent without loss of precision.
max()举例如下:msdn2005上的例子
// numeric_limits_max.cpp
#include <iostream>
#include <limits>
using namespace std;
int main() {
cout << "The maximum value for type float is: "
<< numeric_limits<float>::max( )
<< endl;
cout << "The maximum value for type double is: "
<< numeric_limits<double>::max( )
<< endl;
cout << "The maximum value for type int is: "
<< numeric_limits<int>::max( )
<< endl;
cout << "The maximum value for type short int is: "
<< numeric_limits<short int>::max( )
<< endl;
}
Output
The maximum value for type float is: 3.40282e+038
The maximum value for type double is: 1.79769e+308
The maximum value for type int is: 2147483647
The maximum value for type short int is: 32767
digits()举例:
// numeric_limits_digits_min.cpp
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<float>::digits <<endl;
cout << numeric_limits<double>::digits <<endl;
cout << numeric_limits<long double>::digits <<endl;
cout << numeric_limits<int>::digits <<endl;
cout << numeric_limits<__int64>::digits <<endl;
}
Output
24
53
53
31
63
digits10举例:
// numeric_limits_digits10.cpp
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<float>::digits10 <<endl;
cout << numeric_limits<double>::digits10 <<endl;
cout << numeric_limits<long double>::digits10 <<endl;
cout << numeric_limits<int>::digits10 <<endl;
cout << numeric_limits<__int64>::digits10 <<endl;
}
Output
6
15
15
9
18
- c++中如何返回内置类型的最值——使用
- c++中如何返回内置类型的最值——使用
- 关于c中&的返回值类型
- c——内置类型字面值
- c——内置类型
- Dwr — 如何接收自定义类型的返回值
- 内置类型的返回值具有常性~~~~~~带图片解释!!!!!!
- C/C++中main函数的返回值类型
- c/c++中const成员函数的返回值类型
- c——内置类型提升
- C++内置类型在计算机内存中如何存储的
- 学习C++——返回类型
- c#中如何使用存储过程的返回值
- C#中使用带返回值的存储过程
- Objective-C学习笔记(二十一)——函数的返回值与参数类型
- c——隐式转换——内置类型
- c——运算符——内置类型
- c#如何扩展类型的内置方法
- java泛型与object的比较
- 在线工具 相关
- Discus 论坛 在 pc 电脑上 访问手机版 ( mobile ) 和 触屏版(touch)设置
- centos 解压指令
- windbg学习21(!handle和!cs)
- c++中如何返回内置类型的最值——使用
- TOJ 1883 ZOJ 1298 POJ 1135 Domino Effect / Dijkstra
- 响应时间(response time)和吞吐量(throughput)
- 什么是真正的实时操作系统
- C# JsonHelper
- 【任务笔记】JAVA编程实现对Tomcat上部署项目的监测和控制
- 关于线程(一)线程的基础
- Dynamics CRM 资源
- DIV的内容自动换行