Re: converting exact numbers to binary fixed-point representation
- To: mathgroup at smc.vnet.net
- Subject: [mg58471] Re: converting exact numbers to binary fixed-point representation
- From: Peter Pein <petsie at dordos.net>
- Date: Sun, 3 Jul 2005 03:57:31 -0400 (EDT)
- References: <da5iog$1u4$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Torsten Coym schrieb: > Hi group, > > > what I want to achieve is to represent the exact value of an irrational > number, say Sin[2*Pi*131/8191], as a binary fixed-point number having 16 > fractional (plus one sign bit) bits. > > First, I thought of converting to floating-point value and then > converting to fixed-point using: > > > Floor[N[Sin[2*Pi*(131/8191)]]*2^16] > > Now I'm worried about the precision of this conversion. The piece of > code above truncates all fractional bits that occur after the left shift > operation. The following two intermediate results (I changed to 4 bits > for simplicity here) 1101,000...1 and 1100,111...1 will end up in two > different code words 1101 and 1100, respectively. > Though both values might be equally close to the exact value, the second > would give the wrong solution. So how can I ensure, that *rounding* the > exact value to a floating-point number will never lead to such a case, > that eventually spoils my 16 bit representation? > > Is there a standard way to solve this problem? > Is this a problem at all or am I worried too much? > > Any explanation is welcome. > > Torsten > Try RealDigits[Sin[2*Pi*131/8191],2,16] -- Peter Pein Berlin