Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Multiplication of two fractional numbers

Status
Not open for further replies.

Vardhan2498

Newbie
Newbie level 3
Joined
Oct 22, 2022
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
51
Multiplication of Two Fractional Numbers(Decimal Numbers)

I want to multiply two decimal numbers using verilog (synthesizable code)
A = 0.9
B = 0.9
and want to store result which will be input to a adder

is there any logic which computes multiplication of two decimal numbers?
 

Before you can do calculation with fractional numbers, you have to choose a suitable fixed point number format. https://en.wikipedia.org/wiki/Fixed-point_arithmetic

Most arithmetic code uses fixed point representation with power of two scaling factor, but in this special case, you might use a decimal fixed point format with scaling factor of 0.1;

e.g. 0.9 is represented by integer value 9, 0.9 * 0.9 = 0.81 is represented by integer number 81 (scaling factors are also multilplied).
 
Hi,

It´s not clear what format A and B is.
You say "decimal", but it´s quite unusaul to really use decimal values and decimal math. But surely possible.

It could be fixed point (binary), it could be floating point (binary), BCD, or many other....

Klaus
 

You need to decide your number format, as previously noted. it’s not just a question of multiplying those two numbers, it’s a system question. How much resolution do you need? what’s your dynamic range?
 

Further to what FvM has pointed out in post #2, you need four bits for each of operands A and B, and eight bits (actually resizable in VHDL) for their product. However, whether this will be suitable for you depends on the scaling of the operand that you would be adding their product to.

As an example, lets assume that you are adding their product (0.81, represented as 81 - a scaling factor of 0.01) to another number (still 0.81, represented as 8100 - a scaling factor of 0.0001), you'd realise that your sum will not be correct and of course mere shifting will not help. So you would need to multiply the 81 by 100 (in this specific example) to make the scaling factors the same so the numbers would be suitable for addition.
 
Last edited:

Hello,
My numbers A and B are stored in Reg in Binary format and output is next fed as input to half adder ?
@akamino i have not clearly understood your answer , can you please help me by sending algorithm or code
 

Hi
My numbers A and B are stored in Reg in Binary format
I´d say every data in a nowadays computer is stored in a binary format. It´s always 8 binary bits in a byte.
The question is how you represent it.

Example:
the binary number 0b01000001
* represented as hex 0x41
* as decimal 65
* as character "A"
* as two BCD nibbles 6 and 5
* as fixed point 4.0625 (with 4 fractional bits)
...and so on. All are 8 bits: 0-1-0-0-0-0-0-1

Klaus
 

My numbers A and B are stored in Reg in Binary format and output is next fed as input to half adder ?
@akamino i have not clearly understood your answer , can you please help me by sending algorithm or code

Alternatively I am asking you,
what is the binary value of 0.9 when it is stored in the register A?

If you can answer this someone might answer the 2nd part of your question! :)
 

0.9 in binary is 0.1110
Seems you want to use binary fixed point numbers. But the representation with only 4 fractional bits is rather inaccurate, exact value is 14/16 = 0.875. If you are satisfied with this precision, you should have mentioned earlier.

Any binary fixed point format involves a certain deviation from exact decimal value. You need to specify a number of significant decimal digits and choose the binary bit width respectively.
 

Hi,

I´d expect an 8 bit binary number, but 5 bits surely are possible.
And your first point depicts the place between integer and fractional part.
(I avoid to name it "decimal point" in a binary system)

If so, I see a fixed point binary number with
* 1 bit integer, and
* 4 bits fractional
(We name this in short: Q1.4)

But then the value is not 0.9 but it´s 0.875

If you square a that erroneous number, you also square the error,
so you get 0.1100 (Still using Q1.4) which is 0.75 in decimal (where one expects .9 x 0.9 = 0.81)

There is a lot of information missing.
* count of integer bits
* count of fractinal bits
* signed or unsigned
* both for input and output
* rounding or truncate
* ..

So I recommend to give complete and exact informations.

Klaus

Btw: There are a lot of internet pages, documents, tutorials, even videos on this in the internet.
 

Multiplication of Two Fractional Numbers(Decimal Numbers)

I want to multiply two decimal numbers using verilog (synthesizable code)
A = 0.9
B = 0.9
and want to store result which will be input to a adder

is there any logic which computes multiplication of two decimal numbers?

To be "realistic" you don't need Verilog, just get result manually (precompute), store it in a register then pass it to adder.
 

Guess it's an excercise problem about number formats and Verilog coding. In so far, Verilog is probably "needed".

Unfortunately the problem specification is unclear respectively incomplete, e.g. not telling if a binary or decimal fixed point format is intended and if an exact or rounded number representation is expected.
 

Guess it's an excercise problem about number formats and Verilog coding. In so far, Verilog is probably "needed".

Unfortunately the problem specification is unclear respectively incomplete, e.g. not telling if a binary or decimal fixed point format is intended and if an exact or rounded number representation is expected.
I am of the view that any intuitive exercise should not be misleading but should match actual work in the industry. Otherwise we are not in the right course.

I suggest the forum should have a warning flag from OP when it is exercise. This will help everyone.
 

Hi,

I am of the view that any intuitive exercise should not be misleading but should match actual work in the industry. Otherwise we are not in the right course.
While I understand this opinion, I don´t fully agree with it.

My personal opinion:
* at least 90% should not be misleading
* the rest may be misleading somehow. (but not affect your grading)
There are a couple of reasons for me:
On the one hand you can not look into the future. So if you don´t teach people to look ahead, then this prevents new inventions.
On the other hand it teaches how to deal with problems. Problems not known and never tought.
One hast to find a solution on ones own.
Additionally this encourages to re check your math: I don´t get the expected or the perfect answer: So why is this the case?

Some examples:
When we start with math we learn that one can not divide 6 by 4.
But I think it´s valid to ask this question to pupils. Teacher or pupils maybe have to rephrase it: What happens when if I have 6 apples and want to divide them equally to 4 kids? ... and the solution becomes more "visual".

In the given problem they talk about 0.9 (decimal) to be represented as fractional binary.
But 0.9 never can exactly be represented by a fractional binary. No matter how much bits you use.
(Why and how: in a new thread)
So this - hopefully - teaches you how to deal with this problem. It teaches you to decide - on your own - what precision you need. And especially for engineers it encourages to think about the expectable errors.
like in post#12 ... why the error gets bigger after the multiply operation.

more math:
* finding the 3 solutions for X ^3 = -27 (there is a simple graphical approach --> new thread)

Don´t get me wrong: Not every person in the world needs go this far. But scientists and engineers should learn how to deal with the "unknown".

Klaus
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top