c ++中整数类型的正无穷大和负无穷大 [英] positive and negative infinity for integral types in c++

查看:69
本文介绍了c ++中整数类型的正无穷大和负无穷大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 C++ 中的正无穷和负无穷.

I am reading about positive and negative infinity in c++.

我读到整数类型没有无限值,即.std::numeric_limits<int>::infinity(); 不起作用,但 std::numeric_limits<int>::max(); 会起作用并且将代表整数类型可以表示的最大可能值.

I read that integral types dont have a infinite value ie. std::numeric_limits<int>::infinity(); wont work, but std::numeric_limits<int>::max(); will work and will represent the maximum possible value that can be represented by the integral type.

所以整数类型的 std::numeric_limits::max(); 可以作为它的正无穷极限?

so the std::numeric_limits<int>::max(); of the integral type could be taken as its positive infinite limit ?

或者整数类型只有max valueinfinity value不是真的?

Or the integral type has only the max value and the infinity value is not true ?

推荐答案

浮点数有一个特殊的位模式来表示值是无穷大",当某些运算的结果被定义为无穷大时使用.

Floating point numbers have a special bit pattern to indicate "the value is infinity", which is used when the result of some operation is defined as infinite.

整数值有一定的位数,所有的位数都用来表示一个数值.没有特殊位模式",它只是位位置总和的含义.

Integer values have a set number of bits, and all bits are used to represent a numeric value. There is no "special bit pattern", it's just whatever the sum of the bit positions mean.

在我的 AMD64 架构程序员手册的硬拷贝第 315 页上,它说

On page 315 of my hardcopy of AMD64 Architecture Programmer's Manual, it says

无限.Infinity 是一个正数或负数 +∞和-∞,其中整数位为 1,偏置指数最大,分数为 0. infintes 是最大的数字可以用浮点格式表示,负无穷小比任何有限数和正无穷大大于任何有限数(即仿射意义).

Infinity. Infinity is a positve or negative number +∞ and -∞, in which the integer bit is 1, the biased exponent is maximum and fraction is 0. The infintes are the maximum numbers that can be represented in floating point format, negative infinity is less than any finite number and positive infinity is greater than any finite number (ie. the affine sense).

当一个非零非无限数为除以 0 或乘以无穷大,或无穷大加到无穷大或到 0.算术无穷大是精确的.例如,添加任何浮点数到 +∞给出 +∞ 的结果算术比较适用于无穷大.发生异常仅当使用无穷大作为源操作数构成一个无效操作.

And infinite result is produce when a non-zero, non-infinite number is divided by 0 or multiplied by infinity, or when infinity is added to infinity or to 0. Arithmetic infinites is exact. For example, adding any floating point number to +∞ gives a result of +∞ Arithmetic comparisons work correctly on infinites. Exceptions occur only when the use of an infinity as a source operand constitutes an invalid operation.

(任何打字错误都是我的)

(Any typing mistakes are mine)

这篇关于c ++中整数类型的正无穷大和负无穷大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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