how do I make a portable isnan/isinf function

前端 未结 11 1486
遇见更好的自我
遇见更好的自我 2020-11-29 06:02

I\'ve been using isinf, isnan functions on Linux platforms which worked perfectly. But this didn\'t work on OS-X, so I decided to use std::is

11条回答
  •  粉色の甜心
    2020-11-29 06:24

    I've not tried this, but I would think

    int isnan(double x) { return x != x; }
    int isinf(double x) { return !isnan(x) && isnan(x - x); }
    

    would work. It feels like there should be a better way for isinf, but that should work.

提交回复
热议问题