Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!edcastle!ecwu61 From: ecwu61@castle.ed.ac.uk (R Renwick) Newsgroups: comp.sys.acorn Subject: Dividing Message-ID: <8828@castle.ed.ac.uk> Date: 2 Mar 91 19:47:07 GMT Sender: ecwu61@castle.ed.ac.uk Organization: Edinburgh University Lines: 27 Can anyone help me with this problem: In my super-duper, wire-frame model animating 'C' program, I represent floating point numbers as 4-byte integers. This I do by shifting the number being represented by 15 bits (multiply by 32768) in order that I can keep a track of the fractional part. The reason for doing this is that I want to make sure my program runs as fast as possible by not using floating point arithmetic... What I want to do is do a divide a number by another number and not lose alot of the precision. The way I do this at the moment is by result=((a/b)<<15) But if a and b are close together then (a/b) loses alot of precison (since the result is an int). Does anyone know how I could do an integer division without losing precision. I cannot use result=(((a<<8)/b)<<7) or any other tricks because a may be close to 32768<<15 already... Perhaps if I can find the reciprocal of b in the above representation and multiply it by a then I'll not lose the as much precision, but I don't know how to do this (find the reciprocal) :-( Anyway, if anyone knows how to solve this one, I'd be very grateful to hear from them :-). Rik