Re: [myhdl-list] fixbv to current version of myhdl
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2015-05-02 17:22:32
|
> These are the results I get > python > Python 2.7.3 (default, Sep 26 2013, 20:03:06) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> from myhdl import * > >>> ww = (26,18) > >>> ca1 = fixbv(-1.586134342)[ww] > >>> x2 = fixbv(100.0)[ww] > >>> print ca1 > -1.585938 > >>> print ca1*x2 > -158.593750 Edward, The above results make sense, I need to look into why the fixed -> float (for the print) gave a slightly different value and if it is expected. Explanation: >>> ww = (26,18) # 7 fractional bits >>> ca1 = fixbv(-1.586134342)[ww] >>> print('{}, {}, {}'.format( ca1, repr(ca1), bin(ca1, 26))) -1.585938, fixbv(-1.585938, format=(26,18,7), ), 11111111111111111100110101 From the above we can see the complete word format >>> bv = intbv('11111111111111111100110101')[26:] >>> bin(~bv+1, 26) '00000000000000000011001011' The fractional part is .1001011 which is: >>> 1/2 + 1/16 + 1/64 + 1/128 0.5859375 Given this value, the actual fixed-point value the 100 * -1.5859375 = -158.59375 makes sense. Hope that helps, Chris |