We help IT Professionals succeed at work.

muldiv  long*long/long on 8086

m_sauer
m_sauer asked
on
438 Views
Last Modified: 2008-02-01
Hello Experts,

I am looking for 64-Bit fixed point arithmetic for 16-Bit compilers (borland)
to implement a  function

long muldiv(long a, long b, long c)   // computing (a*b)/c

The problem is there is no 64 arithmetic for the 16-bit compiler.

Any suggestions are welcome

Thanks in advance.

Michael
 
Comment
Watch Question

Commented:
Answer is comming

Commented:
what about
long muldiv(long a, long b, long c)
{
      return(long)(((double)a*(double)b)/(double)c);
}
this will convert a,b,c to double, calculate the value as double
and convert back to long

Commented:
I have a routine (that has been used in a commercial package for years now) that allows for a 48 bit intermediate result (i.e. the multiplication of a and b can be up to 48 bits).
It's not quite the 64 bit intermediate result you asked, on the other hand it is working debugged (Microsoft C) code. It should be easy to adapt. I don't know what kind of numbers you are working with, but 48 bits has been enough in our case.

Let me know if this would be sufficient for your purposes.

Commented:
what about
long muldiv(long a, long b, long c)
{
      return(long)(((double)a*(double)b)/(double)c);
}
this will convert a,b,c to double, calculate the value as double
and convert back to long

Commented:
sorry for duplicate message but the explorer faild the first time
I clicked the submit button

Commented:
goto www.snippets.org

they have source code for long integers arithmetic etc.

Commented:
In particular you will find there

|=============================================================================
| Cliff Rhodes' package of unsigned integer math for arbitrarily large numbers
|=============================================================================
| File         O/S  Description
| ------------ ---  ----------------------------------------------------------
  Bignum.H     any  Header declaring the BigNum struct and prototypes
  Bignum1.C    any  Add, subtract, and multiply BigNum's
  Bignum2.C    any  Divide BigNum's
  Bigtest.C    any  Test and demo program using BigNum's

Commented:
This is arbitrary precision arithmetic .. not 64 bit.

You may need to go to assembly to get efficient 64bit arithmetic.


Author

Commented:
Norbert,
thanks for your suggestion, but this is not really solving my problem.
Double precision floating point is just to slow on the 80188em processor I am using.
It has to be a pure integer solution, as I was asking for.

Thanks anyway.




Author

Commented:
Imladris

the 48-bit routines would be perfect as my intermediate results will fit into that precision.

Please give me some more information!


Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
imladris,

just assuming your routine works right (it's too tricky to judge form the source ), it is an excellent solution for my problem.

thank you very much for your great help.


Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.