scsc Posted April 25, 2021 Report Share Posted April 25, 2021 I dug up this old thread on double(float) conversion to sc_bv: Apparently we can convert a double to sc_ieee_double (see the snippet below from that post) then manually convert to sc_fix(ed) from mantissa and exponent or convert to sc_fixed from the bitvector (with some truncation because the bitvector would have different bitwidth to sc_fixed. But just wonder if there are built in methods that perform the conversion to sc_fixed directly? double d = ...; sc_dt::scfx_ieee_double id(d); // convert to IEEE 754 bitfield // prepare parts bool sgn = id.negative(); sc_dt::sc_uint<11> exp = id.exponent(); sc_dt::sc_uint<53> mnt = ( sc_dt::uint64( id.mantissa1() ) << 20 ) | id.mantissa0(); // concatenate parts to bitvector sc_dt::sc_bv<64> bv = ( sgn, exp, mnt ); Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.