Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: fixed point Date: Tue, 5 Oct 2010 03:27:05 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 41 Message-ID: <i8e5u9$pmg$1@fred.mathworks.com> References: <i8df95$c8j$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-02-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1286249225 26320 172.30.248.37 (5 Oct 2010 03:27:05 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Tue, 5 Oct 2010 03:27:05 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:675852 "Amish Rughoonundon" <axr0284@yahoo.com> wrote in message <i8df95$c8j$1@fred.mathworks.com>... > Hi, > I am getting confused with the way matlab computes fixed point. > I tried to get the fixed point representation of -1.5 two ways > I understand that for the first one is uses the MSB as the sign bit and then the computation is > [-1*(2^0)]+[0*(1/2^1) ] = -1 > > I am totally confused how it's calculating the second one. I would expect it to throw an error since it cannot fit the sign bit on top of two fractional bit in a word length of 2. > Is the word length meaningless. Thanks for any insight. > > >> finum=fi(-1.5,1,2,1) > finum = -1 > DataTypeMode: Fixed-point: binary point scaling > Signedness: Signed > WordLength: 2 > FractionLength: 1 > >> finum.bin > ans =10 > > >> finum=fi(-1.5,1,2,2) > finum = -0.5000 > DataTypeMode: Fixed-point: binary point scaling > Signedness: Signed > WordLength: 2 > FractionLength: 2 > >> finum.bin > ans =10 - - - - - - - - - - - You can't accurately represent -1.5 with fixed point format less than word length 3 bits. With fraction length 1, it would be (in twos complement): -1*2^1 + 0*2^0 + 1*2^(-1) = -1.5 (bits = 1 0.1) With fraction length 2, you would need word length of at least 4: -1*2^1 + 0*2^0 + 1*2^(-1) + 0*2^(-2) = -1.5 (bits = 1 0.1 0) Read the Wikipedia article at: http://en.wikipedia.org/wiki/Two's_complement Roger Stafford