Jump to content
anakin

is_inf() usage for sc_dt::scfx_ieee_float

Recommended Posts

Dear all,

I need to do floating point arithmetic in systemc. 

My question is if after I do two floating point addition or multiplication, can I call this api(is_inf()) for the sum or product to determine

it is inf or not? The produced results looks correct for me. 

Like the following sample code

```c

              num1.negative(sign1);
              num2.negative(sign2);
              num1.exponent(exp1);
              num2.exponent(exp2);
              num1.mantissa(significand1);
              num2.mantissa(significand2);
              //the additiion result
              result = num1+num2;
              cout.precision(23);
              cout << result.is_inf() << " " << num1 << " " << num2 << " " << result << endl;
 

```

 

The following are my test samples:

The first column is is_inf flag, the second and the third column are the source operands and the last column is the produced result.

```

1 -3.402823466385288598117e+38 -3.402823466385288598117e+38 -inf
0 0.5 -0.20000000298023223876953 0.30000001192092895507812
0 0.5 -9.9999997473787516355515e-05 0.49990001320838928222656
0 0.5 -0.30000001192092895507812 0.19999998807907104492188
0 0.5 100 100.5
0 0.5 2003 2003.5
0 0.5 100000 100000.5
0 0.5 -1000000 -999999.5
 

```

 

Any guidance is appreciate.

 

Share this post


Link to post
Share on other sites

This is a C++ question. SystemC is simply a library under C++. Floating point (double & float) are part of C++. There are some implementation bits with IEEE floating point in the current proof of concept source; however, this is not documented nor supported in the official standard presently. Whether or not the is_inf works as defined you could ascertain by examining the source code if you like, but really should not count on it.

If you have questions about fixed point types, those are addressed in the standard.

Please redirect your question to a C++ forum on the topic of floating point. Here is a link <http://www.cplusplus.com/reference/limits/numeric_limits/> of related interest.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×