How to divide by zero without errors

I need to get float NaN and infinity, but I cannot use such constructs

0. / 0. 1. / 0. 

because it causes compilation time

error C2124: division or mod by zero

EDIT, great to have answers where I can get these numbers (+1 for each), but is it possible to divide by zero?

+7
source share
2 answers

You can simply return NaN or infinity, for example:

 return std::numeric_limits<float>::quiet_NaN(); 

or

 return std::numeric_limits<float>::infinity(); 

See std::numeric_limits , from the <limits> header.

+17
source

All Articles