## Floating-point to Fixed-point in (Sharc) DSP

### Floating-point to Fixed-point in (Sharc) DSP

Hello,

I am sure this is a pretty simple question, but I am having some ambiguity
I need to confirm what is happening exactly. Any information is reall
appreciated.

So this is a Sharc DSP I am working with. Question is pretty simple.

Rn = FIX Fx;

FIX description from the manual is as follows:
"Converts the floating-point operand in Fx to a twos-complement 32-bit
fixed-point integer result. If the MODE1 register TRUNC bit=1, the FIX
operation truncates the mantissa towards nfinity. If the TRUNC bit=0,
the FIX operation rounds the mantissa towards the nearest integer. The
TRUNC operation always truncates toward 0. Note that the TRUNC bit
does not influence operation of the TRUNC instruction."

Now the problem is, what is the "floating point OPERAND"?
The mantissa is always a fractional value with one digit left to th
decimal point. For example, the floating point will be something lik
-2.345*(10-5) or 5.678*(10+8), and the mantissa will be 2.345 or 5.678
Now, when it says the mantissa towards -inifinity or nearest integer, tha
means the fixed-point value will be -2 or 5 (according to the above exampl
values)? Which definitely cannot be the case since we have 32-bits.

Cheers.

### Floating-point to Fixed-point in (Sharc) DSP

Your best bet is trying it and examining the result. My guesses are

"operand" is the entire number, which you can consider as a whole in any
base/ Instead of considering the individual bits, Base 10 will make
thinking easier. So 2.644e2 converts to 264.4, which has some binary
representation. (Work it out.) Then apply the truncate/round rules to
the result. The difference between truncating and rounding is either 1 or 0.

Jerry
--
Engineering is the art of making what you want from things you can get.

### Floating-point to Fixed-point in (Sharc) DSP

0.

Thank you Jerry.
Unfortunately I'm just starting out with assembly and am given the task o
finding the algorithm of someone else's code. Unfortunately I hav
experience nor the time to carry this out. I need to understand how
floating-point value will be converted to a "signed integer fixed-point
value to go through the code and report what is happening. I guess i
depends on the DSP I am using too.

Thank you again.

### Floating-point to Fixed-point in (Sharc) DSP

(snip)

It depends on the DSP and the needed range. It is somewhat easier
if you don't need all the bits in the floating point value, as
would be the case with 32 bit float and 16 bit int.

For unsigned 16 bit fixed to 32 bit float, store the int into
the low half of a 32 bit word with the appropriate exponent,
then load it as a floating point value. If there is no
'hidden one', all you need to do is normalize the result,
which adding zero will do on many machines. If there is
a hidden one, then subtract the value with the same exponent
as use previously with all the other bits zero, which will
then normalize the result.

For twos complement, invert the high bit first, which results
in an unsigned value 32768 higher than the original value.
Convert as above, and subtract 32768.

For 32 bit float to 16 bit int, pretty much reverse the above,
though you should check that the value is in range first.

-- glen

### Floating-point to Fixed-point in (Sharc) DSP

of
fixed-point"

Thank you very much Glen.
I think it is what I needed to know. I will go through your explanatio
again and see thourouhly.
And also thank you for that part on inverting the MSB. There was a lin
which did that and I wasn't sure what it was supposed to do.

Thank you heaps.

### Floating-point to Fixed-point in (Sharc) DSP

Not quite. It's binary floating point, so the exponent is in powers of
2. If it's IEEE-like, the mantissa will be unsigned with a sign bit
somewhere in the word. I _think_ IEEE exponents are signed 2-s
compliment, but they may be sign-magnitude as well.

Learning a bit about the floating point representation of the machine
would be a good thing.

Do you have a way to check this on a real machine, preferably with a
de *** ? I can't imagine that's what they mean to do. It would make
far more sense that the conversion is to first calculate where the radix
point* is in the mantissa, make it into an integer + fractional bits,
then truncate or round.

* It's base two, so it's not a decimal point.

--
Tim Wescott
Control system and signal processing consulting
www.wescottdesign.com

### Floating-point to Fixed-point in (Sharc) DSP

IEEE exponents are unsigned, but they have a bias so the an exponent
value of the bias represents a true exponent of 0. The mantissa might
also have a hidden 1 bit, as someone else mentioned.

I agree with that. If they really meant the mantissa and it's binary
floating point, the only possible values of that instruction are 0, +/-1
and +/- 2 (I think). Hardly useful. The conversion surely takes into
account the exponent and probably does what you would think it would do,
so -2.345e-5 becomes 0 and 5.678e8 is 567800000. (Assuming base 10 for
simplicity).

Ray

### Floating-point to Fixed-point in (Sharc) DSP

On 3 jun, 11:07, "m26k9" < XXXX@XXXXX.COM >

Hi,

The operand is Fx. For instance:

R1 = FIX F0;

Converts the floating point value stored in F0 to a fixed point value
stored in R1. Say F0 stores the value 123.456; aplying the above
instruction will store the value 123 in R1.

Could not be easier, thanks to SHARCs!

JaaC

### Floating-point to Fixed-point in (Sharc) DSP

In article < XXXX@XXXXX.COM >,

Start writing the fp numbers as fixed point.
Write those numbers as
- 0.00002345 and 57800000000.0
Truncating towards 0 means leaving off all behind the decimal point.
Towards -infinity means leaving off a .000 or else the highest number
that is still smaller, in those cases:

-1 57800000000

The second number is too large for 32 bits. This probably results in
the largest 32 bit number.
Write a small test program if the manual leaves that unclear.

Groetjes Albert

### Floating-point to Fixed-point in (Sharc) DSP

Dear Tim, Ray, Jaac and Albert.

Thank you so much.
I think I got it now.
The SHARC uses IEEE single-precision format.
So what I need to do is to write is as a decimal without an exponent, an
round it to the possible integer?

For example, the value is 2.345e-5, I write it as 0.00002345, whic
converted to fixed-point will give zero.
If I had 2.345e+5, then I write 234500, so my fixed-point value is 234500.

Thank you very much for the clarification.

Cheers.

### Floating-point to Fixed-point in (Sharc) DSP

Well, except that you do that in binary, instead of decimal.
That is, it is rounded in binary.

-- glen