cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Explorer
Explorer
1,466 Views
Registered: ‎08-31-2017

Comparison of two ap_fixed variables with different bit width

Jump to solution

Hi, dear HLS elites,

 

 I have the following code using if-else to check the value and do corresponding operation. However, it seems the of statement doesn't hold from C simulation. After some debug attempts, I found that if I comment out the if statement and the result is correct. However, I don't know what's wrong with the comparison code in if clause.

Do you find something wrong in the following code  "
  //  if ((in1_t>c5d)  &&  (in1_t <= c6d)) {"?


  ap_fixed<38,21>  in1_t = -3.787282;

  ap_fixed<19,2> c5d = -4;
  ap_fixed<19,2> c6d = -3;
  ap_fixed<19,2> c26d= 0.02739;
   ap_fixed<19,2> c27d= 0.12632;
   ap_fixed<38,21> y1,y2;
 
  //  if ((in1_t>c5d)  &&  (in1_t <= c6d)) {
    y1= c26d*in1_t;
    y2=y1+c27d;
    cout << "Enter c5,c6" << "y1: " << y1 << "  y2: " << y2 << endl;
    
    //  }

 

Thanks

 

All the best,

Nan-Sheng

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Explorer
Explorer
1,773 Views
Registered: ‎08-31-2017

Re: Comparison of two ap_fixed variables with different bit width

Jump to solution

 

 

After some debugging attempts, it was resolved by the alignment as the same variable type for those variables under comparison. Thanks

View solution in original post

0 Kudos
3 Replies
Highlighted
Explorer
Explorer
1,774 Views
Registered: ‎08-31-2017

Re: Comparison of two ap_fixed variables with different bit width

Jump to solution

 

 

After some debugging attempts, it was resolved by the alignment as the same variable type for those variables under comparison. Thanks

View solution in original post

0 Kudos
Highlighted
1,411 Views
Registered: ‎02-03-2018

Re: Comparison of two ap_fixed variables with different bit width

Jump to solution

I am actually quite surprised the ap_int class does not have auto up casting when comparing variable with different precision. Does it mean the safest method to do comparison for two ap_ variable with different precision is to explicitly casting to same format? 

0 Kudos
Highlighted
Explorer
Explorer
1,389 Views
Registered: ‎08-31-2017

Re: Comparison of two ap_fixed variables with different bit width

Jump to solution

 

In this case, I am back to the basics to implement that to resolve since I still don't find efficient coding style to deal with such design problem.

 

Maybe HLS tool team can comment.

0 Kudos