Breaking News
Comments
Oldest First | Newest First | Threaded View
Page 1 / 3   >   >>
sa_penguin
User Rank
Manager
Goldschmidt?
sa_penguin   12/6/2013 7:40:07 PM
NO RATINGS
Sounds a bit like Goldschmidt division: converting the factor 1/10 into X/(2^n). Multiply by X, shift N bits, done. Taking the upper 16 bits of a 32-bit word is equal to a 16-bit shift.

I suspect 1/10 doesn't translate perfectly to binary so, just like 1/3 becomes 0.33... you get a hex factor of 0x1999... in your division.

Brian_D
User Rank
Freelancer
math links
Brian_D   12/6/2013 7:56:58 PM
NO RATINGS
There's some nice material about constant division on the companion website for "Hacker's Delight":

http://www.hackersdelight.org/divcMore.pdf

Also, VHDL has a nifty fixed point math package:

http://www.eda.org/fphdl/

-Brian

krisi
User Rank
CEO
Re: math links
krisi   12/7/2013 10:01:00 AM
NO RATINGS
Pretty cool math...I wonder whether they teach something like that in vlsi classes...Kris

KarlS01
User Rank
Manager
How computers used to do binary multiply and divide
KarlS01   12/7/2013 11:11:18 AM
NO RATINGS
Hi, Tom:  As you said, multiply is a series of additions -- but not dependent on the magnitude of the multiplier, only the number of 1 bits after making both operands positive by complementing if negative.

It is a shift and add sequence starting with the low order bit of the multiplier if it is a 1 add the multiplicand to the double wide product high order and shift right 1 into low order. if multiplier bit is zero, just shift product right one.

Repeat until higher multiplier bits are zero or shifts equal to multipl;ier width. If the high bits are all 0s, then just shift for the remaining word width.

Division was trial subtraction by subtracting the divisore fron the dividend, if the result was positive shift 1 into the quotient high bit else shift 0.  Remainder is left in the reg that held the high order dividend and the quotient in the low order.

If the signs of the dividend and divisor were different, complement at the end.

This is best I remember, maybe a few details missing. The shifts amounted to *2 and /2 and the add/subtract would wind up in the appropriate power of two positions.

I think the constant used in the compiler is 1/10 so they are multiplying by the reciprical of 10 to effectively divide by 10.

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?

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 

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?

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.

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.

 

 

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...

Page 1 / 3   >   >>


EE Life
Frankenstein's Fix, Teardowns, Sideshows, Design Contests, Reader Content & More
Max Maxfield

Some Days You're the Pigeon, Others You're the Statue
Max Maxfield
11 comments
I was watching the travel channel on television the other evening. It was some program about Madrid. The thing I really noticed was the plethora of statues all over the place.

EDN Staff

11 Summer Vacation Spots for Engineers
EDN Staff
20 comments
This collection of places from technology history, museums, and modern marvels is a roadmap for an engineering adventure that will take you around the world. Here are just a few spots ...

Glen Chenier

Engineers Solve Analog/Digital Problem, Invent Creative Expletives
Glen Chenier
15 comments
- An analog engineer and a digital engineer join forces, use their respective skills, and pull a few bunnies out of a hat to troubleshoot a system with which they are completely ...

Larry Desjardin

Engineers Should Study Finance: 5 Reasons Why
Larry Desjardin
46 comments
I'm a big proponent of engineers learning financial basics. Why? Because engineers are making decisions all the time, in multiple ways. Having a good financial understanding guides these ...

Flash Poll
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)