检查inf-Objective-C [英] Check for inf - Objective-C

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

问题描述

例如,当执行1/0运算时,用于测试双精度(或整数)是否为无穷大的方法是什么?

What is the method for testing whether a double (or integer) is infinity, for example when 1/0 operation is performed?

isfinite(n)似乎不起作用.

isfinite(n) does not seem to work.

推荐答案

您可以检查

if(d == INFINITY) {}

if(d > DBL_MAX) {}

INFINITY是在math.h中定义的常量浮点表达式,表示正无穷大;
DBL_MAX是在float.h中定义的常量,代表可以表示的最大双精度数.

INFINITY is a constant float expression defined in math.h representing positive infinity;
DBL_MAX is a constant defined in float.h representing the largest double that can be represented.

此处

这篇关于检查inf-Objective-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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