无限在MSVC ++ [英] Infinity in MSVC++

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

问题描述

我使用MSVC ++,我想在我的代码中使用特殊值INFINITY。

I'm using MSVC++, and I want to use the special value INFINITY in my code.

MSVC ++中无限大的字节模式或常量是什么?

What's the byte pattern or constant to use in MSVC++ for infinity?

为什么1.0f / 0.0f的值为0?

Why does 1.0f/0.0f appear to have the value 0?

#include <stdio.h>
#include <limits.h>

int main()
{
  float zero = 0.0f ;
  float inf = 1.0f/zero ;

  printf( "%f\n", inf ) ; // 1.#INF00
  printf( "%x\n", inf ) ; // why is this 0?

  printf( "%f\n", zero ) ; // 0.000000
  printf( "%x\n", zero ) ; // 0

}


推荐答案

使用 numeric_limits

#include <limits>

float maxFloat = std::numeric_limits<float>::infinity();

这篇关于无限在MSVC ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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