English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

HI,
i wanna multiply two floating point numbers.
But my language does'nt support floating point multiplication.
But it supports integer multiplicationa and all other stuffs.
Ex
a=6
b=7
c=a*b is valid and gives correct answer
if x=2.5
y=3.1
z=x*y ( not allowed) .
Even floating point data i have to take input as string.
There s no support to floating point at all..........

Which language i am using is of no concern.

Let me know.. if its possible to multiply two floating numbers...

Thanks
PC

2007-05-24 01:33:08 · 5 answers · asked by PC 4 in Computers & Internet Programming & Design

Ya.. splitting is easy.
But i need an algorithm which performs the multiplication...
And for the simple answer by ambu . .. . .
will it work in all cases? is it algorithmically correct?

2007-05-24 01:57:41 · update #1

5 answers

An easy technique I have used in 8bit microcontrollers is to shift values left to eliminate decimals, perform the int math then shift right to scale back . There is a loss of accuracy as some bits are lost depending on the ammount of shift.

Example 2.5 * .375 = .9375
.9375 *12.2 =11.4375

shift the decimal points three places each

2500 * 375 = 937500 (Total of 6 shifts right will restor the value

12.2 (shift left 1 becomes 122)

937500 * 122 = 114375000 ( Total of 6 + 1 shifts right will restore to proper scale.)

11.4375000
because integers drop decimals
Your INT answer is 11

Because of binary conversions and limits of 8bit registers the number have to be split into 8 bit chunks but the above gives you and idea of what I mean...

2007-05-24 04:54:55 · answer #1 · answered by MarkG 7 · 1 0

If your language does not support floating point operations directly that means you will have to write your own function to perform floating point operations.

First you will have to split the data (if you are using strings, you can always split at the dot) and perform separate computations for fraction and integer part
You will then have to accumulate the result.
And then you can display the result (may be as a string)

But you will have to write your own function to do this.

2007-05-24 01:39:00 · answer #2 · answered by StarChaser 5 · 1 0

Floating ingredient operations are mathematical calculations performed to numbers that are no longer integers, including numbers with a decimal ingredient. those contain addition, subtraction, multiplication, branch, exponentiation and so on. The degree of flops (floating ingredient operations consistent with 2nd) shows the cost of the equipment to technique such archives. those days, the term is megaflops, gigaflops or teraflops for million, billion or trillion floating ingredient operations consistent with 2nd.

2016-11-26 22:41:55 · answer #3 · answered by ? 3 · 0 0

It is possible if you write an algorithm do long multiplication of each digit in each number ...

2007-05-24 01:39:12 · answer #4 · answered by Anonymous · 1 0

Yes there is....

look:

3.1*2.5 = 7.75
31 * 25 = 775

3.1 => one digit after the floating point
2.5 => one digit after the floating point
7.75 => two digits after the floating point

one + one = two

It is simple, isn't it?

2007-05-24 01:43:25 · answer #5 · answered by Polorado 2 · 0 1

fedest.com, questions and answers