How large is infinity in C?

    

How large is infinity in C?

How large is the infinity in C language?

I found that while using Goolge's OR-Tools

// Create the mip solver with the SCIP backend.
  std::unique_ptr<MPSolver> solver(MPSolver::CreateSolver("SCIP"));
  if (!solver) {
    LOG(WARNING) << "SCIP solver unavailable.";
    return;
  }

  const double infinity = solver->infinity();

In here, I was curious about how large is solver->infinity()? So I found its clarify.

static double infinity() { return std::numeric_limits<double>::infinity(); }

Now, we continue, go deeper:

static _GLIBCXX_CONSTEXPR double
infinity() _GLIBCXX_USE_NOEXCEPT { return __builtin_huge_val(); }

this is in /usr/include/c++/12/limits

Now we Continue to see what is __builtin_huge_val():

#define __builtin_huge_val() __cowchild_cast<double>(0x7ff0000000000000)

I found this in /usr/include/cuda/std/climits, it's obvious that OR-Tools will not call cuda, but the number seems to be same.

So, infinity = 0x7ff0000000000000 in hex, and 9,218,868,437,227,405,312 in dec.

That's funny :).

Only one comment

  1. 建议引入反面案例,增强辩证性。

Add a new comment

  About the blogger

A PhD student in College of Computer Science and Electronic Engineering of Hunan University.

  Recent comments

  •  hofhzqodbd: 情感真挚自然,字里行间传递出强烈的感染力。
  •  zstewsltzd: 选材新颖独特,通过细节描写赋予主题鲜活生命力。
  •  awnuzkstyc: 语言通俗易懂,适合目标读者群体。
  •  alhkeoenkw: 操作步骤清晰,指导性强,易于实践。
  •  wuuyqzgowb: ?实用类评语?
  •  hffpkebrqv: 结论升华部分可联系更高维度价值观。
  •  xxkheclofm: 建议引入反面案例,增强辩证性。
  •  luzfkspnsa: 反驳对手观点时需更注重逻辑严密性。
  •  nishxcwrge: 这是一篇佳作,无论是从内容、语言还是结构上,都堪称完美。
  •  nmgixoplzo: 这篇文章提供了宝贵的经验和见解,对读者有很大的启发和帮助。

Welcome to my website!