Negative infinity

后端 未结 3 1966
情歌与酒
情歌与酒 2020-12-24 06:46

I\'m trying to figure out how to assign the value of negative infinity to a float or double variable. It seems that including the standard library limits, I can get the infi

3条回答
  •  太阳男子
    2020-12-24 07:29

    I don't know what compiler your using, but you can use -std::numeric_limits::infinity() on gcc and MinGw see Infinity-and-NaN. Also I ran the following code on MSVC and it returned true:

    double infinity(std::numeric_limits::infinity());
    double neg_infinity(-std::numeric_limits::infinity());
    double lowest(std::numeric_limits::lowest());
    
    bool lower_than_lowest(neg_infinity < lowest);
    std::cout << "lower_than_lowest: " << lower_than_lowest << std::endl;
    

    However, it maybe worthwhile considering using lowest in your application instead of negative infinity as it's likely to result in a more portable solution.

提交回复
热议问题