i am doing fixed point implementation in c++ and i am trying to define "notanumber" and support a function isnan( ) which returns true if the number is not-a-number and false otherwise.
like the code shown below
Test file
1 2 3 4 5 6 7 8
#include "fixed_point_header.h"
int main()
{
fp::fixed_point<longlongint, 63> a=fp::fixed_point<longlongint, 63>::positive_infinity(); // will assign positive infinity value to a from an function from header
fp::fixed_point<longlongint, 63> b=fp::fixed_point<longlongint, 63>::negative_infinity(); // will assign positive infinity value to b from an function from header
float nan=fp::fixed_point<longlongint, 63>::isnan(a,b);
printf( "fixed point nan value == %f\n", float (nan));
}
In the header i want to do somewhat like the code shown below if positive and negative infinity values are added, the isnan function should return 1 else 0.
fixed point header.h
1 2 3 4 5 6 7 8
#include fixed_point_header
static fp::fixed_point<FP, I, F> isnan (fp::fixed_point<FP, I, F> x,fp::fixed_point<FP, I, F> y){
/*if ( x + y ) happens, ie. x and y are infinities
{
should return 1; }
else {
should return 0; }
} */
return x == fp::fixed_point<FP, I, F>::positive_infinity() &&
y == fp::fixed_point<FP, I, F>::negative_infinity() ||
x == fp::fixed_point<FP, I, F>::negative_infinity() &&
y == fp::fixed_point<FP, I, F>::positive_infinity();
return x == fp::fixed_point<FP, I, F>::positive_infinity() &&
y == fp::fixed_point<FP, I, F>::negative_infinity() ||
x == fp::fixed_point<FP, I, F>::negative_infinity() &&
y == fp::fixed_point<FP, I, F>::positive_infinity();
after which condition i should return these values, can you please explain a bit more detailed how it works?
The way I understand your first post is that you want isnan to take two fixed point numbers x and y. If x is positive infinity and y is negative infinity, or if x is negative infinity and y is positive infinity you want to return true (1) otherwise you want to return false (0). If you put what I wrote as the only thing inside isnan I thought it would do this.