I have a variable float slope that sometimes will have a value of nan when printed out since a division by 0 sometimes happens.
I am trying to do an if-else for when that happens. How can I do that? if (slope == nan) doesn’t seem to work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Two ways, which are more or less equivalent:
Or
(
man isnanwill give you more information, or you can read all about it in the C standard)Alternatively, you could detect that the denominator is zero before you do the divide (or use
atan2if you’re just going to end up usingatanon the slope instead of doing some other computation).