前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >c++_std-numeric_limits极值接口

c++_std-numeric_limits极值接口

作者头像
上善若水.夏
发布于 2019-08-26 09:35:52
发布于 2019-08-26 09:35:52
1.3K0
举报
文章被收录于专栏:上善若水上善若水

std::numeric_limits

在C/C++11中,std::numeric_limits为模板类,在库编译平台提供基础算术类型的极值等属性信息。

用于取代<climits>和<limits.h>,浮点常数定义于<cfloat>和<float.h>。

新的极值概念有两个优点,

  • 一是提供了更好的类型安全性,
  • 二是程序员可借此写出一些template以核定这些极值。

member

member

type

property

is_specialized

bool

true for all arithmetic types (i.e., those for which numeric_limits is specialized). false for all other types.

min()

T

Minimum finite value. For floating types with denormalization (variable number of exponent bits): minimum positive normalized value. Equivalent to CHAR_MIN, SCHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN, FLT_MIN, DBL_MIN, LDBL_MIN or 0, depending on type.

max()

T

Maximum finite value. Equivalent to CHAR_MAX, SCHAR_MAX, UCHAR_MAX, SHRT_MAX, USHRT_MAX, INT_MAX, UINT_MAX, LONG_MAX, ULONG_MAX, LLONG_MAX, ULLONG_MAX, UINT_LEAST16_MAX, UINT_LEAST32_MAX, FLT_MAX, DBL_MAX or LDBL_MAX, depending on type.

lowest()

T

Minimum finite value. (since C++11) For integral types: the same as min(). For floating-point types: implementation-dependent; generally, the negative of max().

digits

int

For integer types: number of non-sign bits (radix base digits) in the representation. For floating types: number of digits (in radix base) in the mantissa (equivalent to FLT_MANT_DIG, DBL_MANT_DIG or LDBL_MANT_DIG).

digits10

int

Number of digits (in decimal base) that can be represented without change. Equivalent to FLT_DIG, DBL_DIG or LDBL_DIG for floating types.

max_digits10

int

Number of digits (in decimal base) required to ensure that values that differ are always differentiated.

is_signed

bool

true if type is signed.

is_integer

bool

测试目标类型是不是可以用整型来表示(比如char是1,float是0

is_exact

bool

true if type uses exact representations.

radix

int

For integer types: base of the representation. For floating types: base of the exponent of the representation (equivalent to FLT_RADIX).

epsilon()

T

返回目标数据类型能表示的最逼近1的正数和1的差的绝对值

round_error()

T

Measure of the maximum rounding error.

min_exponent

int

Minimum negative integer value such that radix raised to (min_exponent-1) generates a normalized floating-point number. Equivalent to FLT_MIN_EXP, DBL_MIN_EXP or LDBL_MIN_EXP for floating types.

min_exponent10

int

Minimum negative integer value such that 10 raised to that power generates a normalized floating-point number. Equivalent to FLT_MIN_10_EXP, DBL_MIN_10_EXP or LDBL_MIN_10_EXP for floating types.

max_exponent

int

Maximum integer value such that radix raised to (max_exponent-1) generates a representable finite floating-point number. Equivalent to FLT_MAX_EXP, DBL_MAX_EXP or LDBL_MAX_EXP for floating types.

max_exponent10

int

Maximum integer value such that 10 raised to that power generates a normalized finite floating-point number. Equivalent to FLT_MAX_10_EXP, DBL_MAX_10_EXP or LDBL_MAX_10_EXP for floating types.

has_infinity

bool

true if the type has a representation for positive infinity.

has_quiet_NaN

bool

true if the type has a representation for a quiet (non-signaling) "Not-a-Number".

has_signaling_NaN

bool

true if the type has a representation for a signaling "Not-a-Number".

has_denorm

float_denorm_style

测试目标类型是不是可以非规范化表示

has_denorm_loss

bool

测试所有类型是不是能测出因为非规范化而造成的精度损失(不是因为结果本身的不精确)

infinity()

T

检查目标类型的无限类型(如果支持无限表示)

quiet_NaN()

T

Representation of quiet (non-signaling) "Not-a-Number", if available.

signaling_NaN()

T

Representation of signaling "Not-a-Number", if available.

denorm_min()

T

Minimum positive denormalized value. For types not allowing denormalized values: same as min().

is_iec559

bool

测试目标类型是不是符合IEC559标准

is_bounded

bool

检查目标类型的取值是否有限

is_modulo

bool

true if the type is modulo. A type is modulo if it is possible to add two positive numbers and have a result that wraps around to a third number that is less.

traps

bool

true if trapping is implemented for the type.

tinyness_before

bool

true if tinyness is detected before rounding.

round_style

float_round_style

Rounding style. A type may have any of the following enum values: round_toward_zero, if it rounds toward zero. round_to_nearest, if it rounds to the nearest representable value. round_toward_infinity, if it rounds toward infinity. round_toward_neg_infinity, if it rounds toward negative infinity. round_indeterminate, if the rounding style is indeterminable at compile time.

sample code

<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" cid="n152" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;" lang="c++">#include<iostream>

include<string>

include<limits>

​ using namespace std; int main(){ cout<<"numeric_limits<int>::min()= "<<numeric_limits<int>::min()<<endl; cout<<"numeric_limits<int>::max()= "<<numeric_limits<int>::max()<<endl; cout<<"numeric_limits<short>::min()= "<<numeric_limits<short>::min()<<endl; cout<<"numeric_limits<short>::max()= "<<numeric_limits<short>::max()<<endl; cout<<"numeric_limits<double>::min()= "<<numeric_limits<double>::min()<<endl; cout<<"numeric_limits<double>::max()= "<<numeric_limits<double>::max()<<endl; ​ cout<<"numeric_limits<int>::is_signed()= "<<numeric_limits<int>::is_signed<<endl;//是否有正负号 cout<<"numeric_limits<string>::is_specialized()= "<<numeric_limits<string>::is_specialized<< endl;//是否定义了数值极限 system("pause"); return 0; } </pre>

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019.08.25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
wireshark解析自定义的protobuf协议
wireshark是开源的,而且在Windows下安装时用的是64位,所以相应的库文件需要使用64位。
meteoric
2018/11/20
4.5K0
Lua编写wireshark插件初探——解析Websocket上的MQTT协议
一、背景 最近在做物联网流量分析时发现, App在使用MQTT协议时往往通过SSL+WebSocket+MQTT这种方式与服务器通信,在使用SSL中间人截获数据后,Wireshark不能自动解析出MQTT语义,只能解析到WebSocket层,如图所示。虽然在Data域中显示了去掉mask的WebSocket数据,但分析起来mqtt仍然很难受。所以打算写一个插件,利用wireshark自带的MQTT解析功能来分析Data部分的数据,而不是自己从头写一个完全新的解析器。注:很多教程是教如何添加一个新的协议,如设
ascii0x03
2018/04/12
3.9K0
Lua编写wireshark插件初探——解析Websocket上的MQTT协议
从零到一实现 RocketMQ 的 Wireshark Lua 插件
学习 RocketMQ,需要搞懂两个东西:通信和存储。这里花了一点时间写了一个 RocketMQ 的 wireshark lua 插件,过程挺有意思,写出来记录一下。
挖坑的张师傅
2022/05/13
6520
从零到一实现  RocketMQ  的 Wireshark Lua 插件
【最详细】Wireshark使用教程
到wireshark官网下载你所需要的版本,官网地址https://www.wireshark.org,选择下载,跟进自己的操作系统选择。
未名编程
2024/10/12
1.6K0
【最详细】Wireshark使用教程
Wireshark抓取Websocket的mqtt报文
本文档记录,如何使用Wireshark抓包工具,抓取基于Websocket的MQTT报文。
yield9tk
2022/03/05
3.4K0
Wireshark从入门到放弃
Wireshark的启动很简单,我们可以在开始菜单中找到Wireshark的图标,或者在终端执行Wireshark命令即可。 进入到wireshark工具的首页界面,会让我们选择要监听的网卡。选择我们的监听的网卡。直接双击即可。
逍遥子大表哥
2022/04/25
1.9K2
Wireshark从入门到放弃
实战编写 wireshark 插件解析私有协议
在对嵌入式设备进行分析时,有时会遇到一些私有协议,由于缺少对应的解析插件,这些协议无法被Wireshark解析,从而以原始数据的形式呈现,不便于对协议的理解与分析。正好之前看到了介绍用Lua脚本编写Wireshark协议解析插件的文章:
信安之路
2020/09/11
7K0
数据包分析基础
在数据包的分析中离不开的工具就是wireshark, 这里整理一下重要的几个功能:
后场技术
2020/12/14
1.3K0
数据包分析基础
网络工程师的高端玩具:WireShark 从入门到精通,收藏!
抓包应该是每个技术人员掌握的基础知识,无论是技术支持运维人员或者是研发,多少都会遇到要抓包的情况,用过的抓包工具有fiddle、wireshark,作为一个不是经常要抓包的人员,学会用Wireshark就够了,毕竟它是功能最全面使用者最多的抓包工具。
网络技术联盟站
2023/03/01
1.2K0
网络工程师的高端玩具:WireShark 从入门到精通,收藏!
wireshark抓包分析
wireshark是非常流行的网络封包分析软件,功能十分强大。可以抓取各种网络包,并显示网络包的详细信息。
业余草
2019/01/21
2.1K0
wireshark抓包分析
Wireshark 网络抓包工具
wireshark是一款网络流量抓取分析神器,也是安全工具使用排行中排名第一的工具。使用wireshark必须要牢记一些常用的数据包过滤规则,对于寻找一些特定的包会事半功倍。
Xcnte
2021/12/14
4640
Wireshark 网络抓包工具
wireshark抓包工具详细说明及操作使用_wireshark ping抓包
wireshark是非常流行的网络封包分析软件,功能十分强大。可以截取各种网络封包,显示网络封包的详细信息。使用wireshark的人必须了解网络协议,否则就看不懂wireshark了。 为了安全考虑,wireshark只能查看封包,而不能修改封包的内容,或者发送封包。
全栈程序员站长
2022/10/04
1.4K0
wireshark抓包工具详细说明及操作使用_wireshark ping抓包
Python黑帽编程1.5 使用Wireshark练习网络协议分析
1.5.0.1 本系列教程说明 本系列教程,采用的大纲母本为《Understanding Network Hacks Attack and Defense with Python》一书,为了解决很多同学对英文书的恐惧,解决看书之后实战过程中遇到的问题而作。由于原书很多地方过于简略,笔者根据实际测试情况和最新的技术发展对内容做了大量的变更,当然最重要的是个人偏好。教程同时提供图文和视频教程两种方式,供不同喜好的同学选择。 1.5.0.2 本节前言 在上一节,笔者罗列的学习网络编程应该了解或掌握的网络基础知识
用户1631416
2018/04/12
1.3K0
Python黑帽编程1.5  使用Wireshark练习网络协议分析
Python编写渗透工具学习笔记二 | 0x04编写程序分析流量检测ddos攻击
0x04编写程序分析流量 检测ddos攻击 1使用dpkt发现下载loic的行为 LOIC,即Low Orbit Ion Cannon低轨道离子炮,是用于压力测试的工具,通常被攻击者用来实现DDoS攻击。 我们要编写py脚本来解析http流量,并检查其中有无通过http get获取压缩过的loic二进制可执行文件的情况。为了检查http流量,我们必须先把数据包的以太网部分、ip层以及tcp层部分分解出来,注意http协议是位于tcp协议层之上的。如果http层中使用了get方法,则解析http get所要获
安恒网络空间安全讲武堂
2018/02/06
3.4K0
Python编写渗透工具学习笔记二 | 0x04编写程序分析流量检测ddos攻击
wireshark过滤规则及使用方法
ip.src eq 192.168.1.107 or ip.dst eq 192.168.1.107
全栈程序员站长
2022/09/14
1.9K0
wireshark过滤规则及使用方法
Wireshark 常用的几个过滤写法
一站式学习Wireshark,具体详见链接:http://bltog.jobbole.com/70907/ 这里直接略过
保持热爱奔赴山海
2019/09/18
2.1K0
爬虫遇到 Socket,莫慌,肝就完了!
Socket 被称为套接字,是对 TCP/IP 协议的封装,它是传输层和应用层间的抽象层
AirPython
2020/12/02
9970
爬虫遇到 Socket,莫慌,肝就完了!
一些wireshark过滤表达式
过滤协议 捕获http协议 http 捕获不是http协议 not http 捕获udp或tcp udp or tcp 过滤端口号 捕获tcp的某一个端口号 tcp.port == 21 捕获udp的某一范围的端口号 udp.port >= 10000 过滤地址 捕获发送(源)地址 ip.src == 192.168.1.1 捕获接收(目标)地址 ip.dst == 192.168.1.1 捕获源或目标地址 ip.addr == 192.168.1.1 等价于 ip.src == 192.168.1.1
Qt君
2023/03/17
4010
一些wireshark过滤表达式
【愚公系列】《网络安全应急管理与技术实践》 011-网络安全应急技术与实践(网络层-Wireshark进行无线监听重现分析)
Wireshark是一款网络协议分析工具,可以帮助用户捕获和分析网络数据包。在无线网络环境中,Wireshark可以用来监听和分析无线网络流量,帮助用户了解网络中的通信情况和问题。
愚公搬代码
2024/09/16
2500
Redis哨兵机制全面深入分析与讲解[实战演示篇]
本文将通过理论+实践的方式从头到尾总结Redis中的哨兵机制。文章内容从主从复制的弊端、如何解决弊端、什么是哨兵、哨兵监控的图形结构、哨兵监控的原理、如何配置哨兵、哨兵与主从复制的关系等方面来演示。本文演示如何自建一个Redis哨兵机制。推荐使用腾讯云服务器,腾讯云Redis服务等产品。
兔云小新LM
2021/04/18
1.6K0
Redis哨兵机制全面深入分析与讲解[实战演示篇]
推荐阅读
相关推荐
wireshark解析自定义的protobuf协议
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档