I have to get input in float as +NaN or -NaN and convert to another artificial floating form called tinyfp (1 sign bit, 3 exponent bits, 4 fraction bits) for one question,
or get input in the tinyfp (each presenting +NaN or -NaN) and answer as either +NaN or -NaN
The question specifically asks
+NaN and -NaN in float should be converted to the corresponding +NaN and -NaN in tinyfp, respectively.
and
+NaN and -NaN in tinyfp should be converted to the corresponding +NaN and -NaN in float, respectively.
The first problem is, since I cannot compare NaN to anything (even itself), while I can identify if input value is NaN, I cannot distinguish between +NaN and -NaN.
Similar with second problem, when I want to answer as either +NaN or -NaN, both 0.0/0.0 and -0.0/0.0 are represented as -NaN, so I cannot answer anything as +NaN.
I tried if( input == 0.0/0.0) or (input == -0.0/0.0), and they don't work.
I can try if(input != input), but then I can't distinguish +NaN and -NaN.
For the second problem, I tried return 0.0/0.0 and return -0.0/0.0, but both end up answering as -NaN. (while somehow I can get input as both nan and -nan)
So the question is, how do I check if input is +NaN or -NaN, and how do I assign +NaN and -NaN differently when I want to answer as NaN?
I'm not allowed to use any header other than stdio.h + and I can't use double format as well - only float allowed