建模最大双值的无穷大 [英] Modeling infinity for the largest double value

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

问题描述

问题是在C ++中为 double 数据类型建模无穷大。我需要它在一个头文件,所以我们不能使用函数 numeric_limits

The question is about modeling infinity in C++ for the double data type. I need it in a header file, so we cannot use functions like numeric_limits.

是否有定义的常数,代表最大值?

Is there a defined constant that represents the largest value?

推荐答案

浮点数(例如双精度)可以实际上保持正和负无穷大。

floating point numbers(such as doubles) can actually hold positive and negative infinity. The constant INFINITY should be in your math.h header.

常规标准潜水,并找到文本:

Went standard diving and found the text:


4宏INFINITY扩展为float
类型的常量表达式,表示正或无符号无穷大(如果可用)

4 The macro INFINITY expands to a constant expression of type float representing positive or unsigned infinity, if available; else to a positive constant of type float that overflows at translation time.

7.12节中, Mathematics< math.h>

然后当然你有辅助函数 isinf 以测试无穷大(也在math.h中)。

Then of course you have the helper function isinf to test for infinity(which is also in math.h).


7.12。 3.3 isinf宏

7.12.3.3 The isinf macro

int isinf(real-floating x);

int isinf(real-floating x);

描述:isinf宏确定其参数值是无穷大(正
还是负数)。首先,以大于
的格式表示的参数的语义类型被转换为其语义类型。然后
确定是基于参数的类型。

Description: The isinf macro determines whether its argument value is an infinity (positive or negative). First, an argument represented in a format wider than its semantic type is converted to its semantic type. Then determination is based on the type of the argument.

返回:
isinf宏当且仅当其参数具有
无限值时返回非零值。

Returns: The isinf macro returns a nonzero value if and only if its argument has an infinite value.

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

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