Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to find exponent and mantissa from a Q Format

Reply
Thread Tools

How to find exponent and mantissa from a Q Format

 
 
sankar
Guest
Posts: n/a
 
      11-23-2005
Hi,

I am using a Q14.18 value. There are tables used
in my program which are being indexed by the exponent and mantissa
parts of the corresponding floating point value.

So how can I get the exponent and mantissa parts of a floating point
number from its Q format representation.


Please do help.
TIA.
--
Arun

 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      11-23-2005
"sankar" <> writes:
> I am using a Q14.18 value. There are tables used
> in my program which are being indexed by the exponent and mantissa
> parts of the corresponding floating point value.
>
> So how can I get the exponent and mantissa parts of a floating point
> number from its Q format representation.


Standard C has nothing called "Q14.18" or "Q format". If you can
specify the format, we might be able to help.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      11-23-2005
Keith Thompson said:

> Standard C has nothing called "Q14.18"


Yeah, it stops at Q14.13

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
Brad Griffis
Guest
Posts: n/a
 
      11-23-2005
sankar wrote:
> Hi,
>
> I am using a Q14.18 value. There are tables used
> in my program which are being indexed by the exponent and mantissa
> parts of the corresponding floating point value.
>
> So how can I get the exponent and mantissa parts of a floating point
> number from its Q format representation.
>
>
> Please do help.
> TIA.
> --
> Arun
>


I have only seen the "Q" notation used for doing fixed-point math. That
is, a Q14.18 number has 14 binary digits to the left of the implied
decimal point and 18 digits to the right of the implied decimal point.
You are talking about floating point, exponents, and mantissas. The
fixed point terminology would involve an integer and a fractional piece.
I've never heard anyone apply this terminology to floating point. Is
that truly what you're doing or are you using the wrong terms? In fixed
point you would just right-shift this number by 18 and you've got your
index.

Brad
 
Reply With Quote
 
Tim Olson
Guest
Posts: n/a
 
      11-24-2005
In article <. com>,
"sankar" <> wrote:

| Hi,
|
| I am using a Q14.18 value. There are tables used
| in my program which are being indexed by the exponent and mantissa
| parts of the corresponding floating point value.
|
| So how can I get the exponent and mantissa parts of a floating point
| number from its Q format representation.

You would be better off asking this question in comp.dsp, where dealing
with fixed-point (Q-format) numbers is common.

Q14.18 specifies a fixed-point value of 32 bits with a 14-bit integer
and 18-bit fraction, usually in 2's-complement (signed) format.

To get the equivalent floating-point value, you need to first get the
magnitude by taking the 2's complement of the value if the sign bit is
set. Then "normalize" the Q14.18 value by shifting it left until the
most-significant bit is a '1', and counting the number of times you
shift. The exponent is then:

14 - shift_amount - 1

and the mantissa is the value after you normalize in 1.31 format.

Example:

value = 26.85

Q14.18 representation = 00000000011010.110110011001100110

shift left 9 times to get a '1' in the most-significant bit:

11010110110011001100110000000000

exponent is 14-9-1 = 4

mantissa is 1.1010110110011001100110000000000


-- Tim Olson
 
Reply With Quote
 
Jerry Avins
Guest
Posts: n/a
 
      11-24-2005
Tim Olson wrote:
> In article <. com>,
> "sankar" <> wrote:
>
> | Hi,
> |
> | I am using a Q14.18 value. There are tables used
> | in my program which are being indexed by the exponent and mantissa
> | parts of the corresponding floating point value.
> |
> | So how can I get the exponent and mantissa parts of a floating point
> | number from its Q format representation.
>
> You would be better off asking this question in comp.dsp, where dealing
> with fixed-point (Q-format) numbers is common.
>
> Q14.18 specifies a fixed-point value of 32 bits with a 14-bit integer
> and 18-bit fraction, usually in 2's-complement (signed) format.
>
> To get the equivalent floating-point value, you need to first get the
> magnitude by taking the 2's complement of the value if the sign bit is
> set. Then "normalize" the Q14.18 value by shifting it left until the
> most-significant bit is a '1', and counting the number of times you
> shift. The exponent is then:
>
> 14 - shift_amount - 1
>
> and the mantissa is the value after you normalize in 1.31 format.
>
> Example:
>
> value = 26.85
>
> Q14.18 representation = 00000000011010.110110011001100110
>
> shift left 9 times to get a '1' in the most-significant bit:
>
> 11010110110011001100110000000000
>
> exponent is 14-9-1 = 4
>
> mantissa is 1.1010110110011001100110000000000


And in most floating-point formats, the 1 before the binary point is
omitted from storage, reinserted by the ALU.

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: mantissa and exponent in base 10 C or L Smith Python 0 10-08-2010 01:43 PM
Re: mantissa and exponent in base 10 C or L Smith Python 0 10-07-2010 03:51 PM
mantissa and exponent in base 10 Steven D'Aprano Python 3 10-07-2010 11:11 AM
XSLT / XPATH 2.0 split float to exponent / mantissa and find nearestengineering format RolfK XML 1 01-20-2009 03:00 PM
exponent format. adahili@gmail.com C++ 1 10-07-2005 05:01 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57