How to avoid NaN in C++ [duplicate] - c++

This question already has answers here:
Checking if a double (or float) is NaN in C++
(21 answers)
Closed 4 years ago.
of course I know I should write better code which just not create NaN values.
But is there any casual method to avoid it. I mean something like:
if (!(floatNumber == NaN))
// do some stupid function
else
return;
But it doesn't work for me. I also tried floatNumber==null, but also no result.
Could you please help me?

To test whether a number is NaN, you can use the standard library function std::isnan.

Related

Optimizing pow algorithm [duplicate]

This question already has answers here:
Optimizations for pow() with const non-integer exponent?
(10 answers)
Closed 9 years ago.
I have to raise a number to the power of 1/2.2 which is 0.45454545... many times. Actually I have to do this in a loop. Simple pow/powf is very slow (when I comment out this pow from my loop code it's a loot faster). Is there any way to optimize such operation?
You might give a look at: Optimized Approximative pow() in C / C++
It also includes a benchmark.

How to generate a random number between 0 and a user-defined integer in C/C++? [duplicate]

This question already has answers here:
Generating a random integer from a range
(14 answers)
Closed 9 years ago.
I'm having a problem with my code, in which I try to generate a number between 0 and a dim user-defined variable. The line I'm having problem is:
arrayPos = rand()%dim;
I already called srand(time(NULL)) and the arrayPos is getting some wierd numbers like 9.267e-315 and so on.
Any ideas on how to fix it?
Thank you
The problem really was garbage memory, I restarted the computer and it worked like a charm

What is an equivalent to instanceof in C++? [duplicate]

This question already has answers here:
C++ equivalent of java's instanceof
(5 answers)
Closed 9 years ago.
How can I check the class type in c++?
In Java I used instanceof.
I prefer not to use dynamic cast, but only classic c++.
Is there any way?
Clarification:
It isn't a duplicate of another question in StackOverflow, since I asked how can I find it without using of dynamic_cast. In the other question, the answer was to use it. Please don't mark it as a duplicated.
There is no way to check class type without RTTI or it's home brew substitution. If application compiled without RTTI information about type is not stored anywhere.

What does DIST=AMAX1(0.,DI-DJ) means in Fortran? [duplicate]

This question already has an answer here:
What is meant by . usage after a number in Fortran?
(1 answer)
Closed 3 years ago.
I'm trying to understand a code in fortran language and i don't understand what does
DIST=AMAX1(0.,DI-DJ) means.
I am really confused with the dot(.) next to 0 .
Any help would be appreciated.
Thanks in advance
MAria
AMAX1 is a function for obtaining the maximum value of two or more (single precision) floating point values. The . is there to indicate that the argument is a floating point value and not an integer. 0. is short for 0.0, FORTRAN allows you to omit the decimal zero.
There are lots of FORTRAN references on the Internet. Here is a quick list of intrinsic functions, for example.

C++ Suggesting wrong spelled words [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What algorithm gives suggestions in a spell checker?
What algorithm should be used in a C++ program whose aim is to read from a text file and give suggestions for the wrong spelled words ?
Use the Levenshtein distance:
http://thetechnofreak.com/technofreak/levenshtein-distance-implementation-c/
http://murilo.wordpress.com/2011/02/01/fast-and-easy-levenshtein-distance-using-a-trie-in-c/