Can an integer be NaN in C++?

前端 未结 5 1980
孤城傲影
孤城傲影 2020-12-03 13:26

Can I set an int to NaN? If yes, then how can I check if an int is NaN or not?

5条回答
  •  不知归路
    2020-12-03 14:01

    I think the most proper API to handle failures is to return a second integer error code in your api like:

    int myfunc(args, int* realReturn);
    

    The returned int is an error code.

    The previous output is passed as a pointer in calling code:

    int myInt;
    if (myFunc(args, &myInt) != 0) {
    //handle error
    }
    

提交回复
热议问题