Breaking News
Comments
Newest First | Oldest First | Threaded View
<<   <   Page 2 / 3   >   >>
Adam-Taylor
User Rank
Blogger
How FPGA do math
Adam-Taylor   12/8/2013 7:22:29 AM
Hi Tom

good blog, I wrote an article on this for Xcell a few years ago hope you do not mind me linking to it here

 

http://www.eetimes.com/document.asp?doc_id=1279807

sa_penguin
User Rank
Manager
Re: Fractional arithmetic
sa_penguin   12/7/2013 7:50:19 PM
NO RATINGS
I broke out Excel and did some quick fractions.

For a 12-bit number: 1/10 = 409.6/4096 and 410 = 19AH
16 bits: 1/10 = [6,553.6] / [65,536]  and 6,554 = 199AH
24 bits: 1/10 = [1,677,721.6] / [16,777,216] and 1,677,722 = 19 999AH

Yes, I have a habit of putting commas in decimal numbers and spaces in hex numbers. I find it makes them easier to distinguish.

tom-ii
User Rank
Blogger
Re: math links
tom-ii   12/7/2013 5:49:11 PM
NO RATINGS
Brian,

 

Interesting stuff.  To be honest, though, I'm a complete n00b, and am teaching myself Verilog at this point.

tom-ii
User Rank
Blogger
Re: Fortran is lying to you
tom-ii   12/7/2013 5:48:22 PM
NO RATINGS
@AZskibum:

 

Fractional fixed point (often referred to as "Q" format) is efficient -- you choose exactly the precision you need, no less and no more -- and the bookkeeping exercise of keeping track of the radix point is not a big deal.

 

This is actually what I used in my final implementation - We'll get to that in a few weeks, I suppose....  (Max willing)

tom-ii
User Rank
Blogger
Re: Fractional arithmetic
tom-ii   12/7/2013 5:45:42 PM
NO RATINGS

@dtejada201


I figured as much, but just hadn't actually sat down and worked it out.  Without knowing for a fact, I didn't want to spout complete nonsense. 

 

...

 

I spout enough nonsense as it is...

tom-ii
User Rank
Blogger
Re: Goldschmidt?
tom-ii   12/7/2013 5:43:27 PM
NO RATINGS
These are clever tricks, but why are you stuck on dealing with base 10, when ultimately you're implementing all the operations with shifts, adds & subtracts in base 2?

 

I didn't intend to imply that I was stuck with base 10.  Base 10 is just natural for us humans, and there are plenty of applications that use it a lot, especially when the end result is decimal math.  In this specific application, I am sending the computation engine decimal numbers, and expecting them in return.  It was worth my while to run down the rabbit hole to see if there was an immediately easy way to get it done this way.

 

 

AZskibum
User Rank
CEO
Re: Fortran is lying to you
AZskibum   12/7/2013 4:25:49 PM
NO RATINGS
Not only do floating point numbers not obey associativity, they also lack precision. Sure, if 24 bits of precision doesn't meet your needs, you can go to double precision, but both formats are wasteful when your doing arithmetic in hardware.

Fractional fixed point (often referred to as "Q" format) is efficient -- you choose exactly the precision you need, no less and no more -- and the bookkeeping exercise of keeping track of the radix point is not a big deal.

betajet
User Rank
CEO
Fortran is lying to you
betajet   12/7/2013 2:49:25 PM
NO RATINGS
Floating-point numbers are not real numbers.  Real numbers obey the associative law of addition.  Floating-point numbers do not.  Try adding 1 to an accumulator 10^9 times with six-digit floating point.  Once the accumulator has reached 10^6, adding more ones doesn't change the accumulator, so the sum of 10^9 ones is 10^6 instead of 10^9.  If you add the 1's in groups of 10, and then add those sums in groups of 10, and so on, you'll get the correct value.  However, since the result depends on the order of addition, the floating-point numbers violate the associative law.  Don't expect floating-point to behave like real numbers without considering these effects.

Non-negative integers, OTOH, do behave mathemically like modulo 2^n numbers so you do get the correct result modulo 2^n.

I agree with the above poster regarding using a decimal radix.  Why not use base 2 like IEEE floating point or base 16 like IBM/360?

dtejada201
User Rank
Rookie
Fractional arithmetic
dtejada201   12/7/2013 1:13:51 PM
The way I look at this is as a modified form of Q15 arithmetic.  For starters, I can represent a fractional number as a 16 bit fixed point signed integer by the following relationship:

-32768 <--> -.5
 32768 <-->  .5

Thus .5 is 0x 7FFF (almost).  To get .1, I divide by 5 and .1 is 0x199A.  This is where the 0x199A factor comes from.   When I multiply 2 Q15 numbers, I get a 32 bit result a 32-bit Q31 result.  This means .25*.1 is as follows:

.25 => 0x4000
.1   => 0x199A

0x4000 * 0x199A => 0x06668000
0x666800 >> 16 is 0x0666 => which corresponds to .025

Hope this helps 

AZskibum
User Rank
CEO
Re: Goldschmidt?
AZskibum   12/7/2013 11:52:18 AM
NO RATINGS
These are clever tricks, but why are you stuck on dealing with base 10, when ultimately you're implementing all the operations with shifts, adds & subtracts in base 2?

<<   <   Page 2 / 3   >   >>


Flash Poll
EE Life
Frankenstein's Fix, Teardowns, Sideshows, Design Contests, Reader Content & More
Engineer's Bookshelf
Caleb Kraft

The Martian: A Delightful Exploration of Math, Mars & Feces
Caleb Kraft
3 comments
To say that Andy Weir's The Martian is an exploration of math, Mars, and feces is a slight simplification. I doubt that the author would have any complaints, though.

The Engineering Life - Around the Web
Caleb Kraft

Surprise TOQ Teardown at EELive!
Caleb Kraft
Post a comment
This year, for EELive! I had a little surprise that I was quite eager to share. Qualcom had given us a TOQ smart watch in order to award someone a prize. We were given complete freedom to ...

Design Contests & Competitions
Caleb Kraft

Join The Balancing Act With April's Caption Contest
Caleb Kraft
54 comments
Sometimes it can feel like you're really performing in the big tent when presenting your hardware. This month's caption contest exemplifies this wonderfully.

Engineering Investigations
Caleb Kraft

Frankenstein's Fix: The Winners Announced!
Caleb Kraft
8 comments
The Frankenstein's Fix contest for the Tektronix Scope has finally officially come to an end. We had an incredibly amusing live chat earlier today to announce the winners. However, we ...

Top Comments of the Week
Like Us on Facebook
EE Times on Twitter
EE Times Twitter Feed

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)