Skip to main content
GameDev.net gamedev.net
🔒 Locked

Returning a NaN

Started by Auron Jan 19, 2005 at 10:24 PM 1 replies 700+ views
Original Post
Auron
Auron
I'm programming some general purpose 2D math stuff and I have a Line class. One of the methods in that class returns the slope of the line. If a line is vertical, it will have a slope of infinity. Is there any reliable way to return a NaN or Inf value from a function without the possibility of raising an exception or other run-time error? Since I've heard that generating a NaN/Inf is very implementation specific, you'll probably want to know I'm presently coding in Visual C++ Express but I will soon have to port the code to GCC for Linux. -Auron
XXX_Andrew_XXX
XXX_Andrew_XXX
Use the STL to get a platform independant value

#include <limits>#include <iostream>using std::cout;using std::endl;int main(){    cout << std::numeric_limits<double>::infinity() << endl;    cout << std::numeric_limits<double>::signaling_NaN() << endl;}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.