Board index » delphi » Fixed Point Math in Delphi
l...@mosoft.se (Lars G. Oerne)
Delphi Developer 
Wed, 03 Jun 1998 03:00:00 GMT

l...@mosoft.se (Lars G. Oerne)
Delphi Developer 
Wed, 03 Jun 1998 03:00:00 GMT
Fixed Point Math in DelphiQuote> dauwa...@tempest.adsnet.net (Tyler Dauwalder) writes: HTH /LG ____________________________________________________ 
Tyler Dauwald
Delphi Developer 
Wed, 03 Jun 1998 03:00:00 GMT
Re:Fixed Point Math in DelphiI'm having trouble implementing fixed point math in Delphi. I've been translating from a book that explains it in C, and I can't figure out how to assign values to a fixed point number. The book's example (in C) is this: Long Fix_1 = (long)(23.45 * 256); It explains that you assign values by doing a typecast. Attempting a  
Michael Chap
Delphi Developer 
Thu, 04 Jun 1998 03:00:00 GMT
Re:Fixed Point Math in DelphiIn article <4aucn9$...@mn5.swip.net>, l...@mosoft.se (Lars G. Oerne) wrote: Quote> dauwa...@tempest.adsnet.net (Tyler Dauwalder) writes: what I use. Function RealToFixed(x : Real) : FixedPoint;  
Kerry Sande
Delphi Developer 
Fri, 05 Jun 1998 03:00:00 GMT
Re:Fixed Point Math in DelphiQuotemcha...@vcn.com (Michael Chapin) wrote: }> could find explained in the help files. So, does anyone else know how to }> assign a floating point value to a fixed point number? Also, if so, how }> would I then read that value? } }My news reader has been acting up lately so I missed the first post. Here's }what I use. } }Function RealToFixed(x : Real) : FixedPoint; }Begin } x := x * 65536.0 + 0.49; } RealToFixed := Round(x); }End; I caught this reponse that you gave to someone in the newsgroup, and I was 
Jon Shemi
Delphi Developer 
Sat, 06 Jun 1998 03:00:00 GMT
Re:Fixed Point Math in DelphiIn article <4au050$...@news1.wolfe.net>, QuoteTyler Dauwalder <dauwa...@tempest.adsnet.net> wrote: Fix_1: LongInt = Round( 23.45 * 256 ); Quote> It explains that you assign values by doing a typecast. Attempting a imply a call to a type conversion function. (In C++, you can even specify this function.) Thus, you can typecast a float to an integer. In Delphi, you can only typecast between likesized types: A typecast is _________________________________________________________________________ Larger Question Time: Why Are You Still Bothering With FixedPoint? I've done a fair amount of fixedpoint math in my day, but I don't do much About the only fixedpoint I do anymore is MulDiv(A, B, C) for (A * B) / C Note to anyone who's still following: http://www.armory.com/~jon Personal Pages 
Jon Shemi
Delphi Developer 
Sun, 07 Jun 1998 03:00:00 GMT
Re:Fixed Point Math in DelphiQuoteIn article <4b71b5$...@news.scruz.net>, Jon Shemitz <j...@armory.com> wrote: fixed point code which is five times slower; the 386mode singleprecision 32bit fixed point code is "only" ca 35% slower than the 387 version.  http://www.armory.com/~jon Personal Pages 
Bengt Richt
Delphi Developer 
Tue, 09 Jun 1998 03:00:00 GMT
Re:Fixed Point Math in DelphiQuoteksand...@bham.mindspring.com (Kerry Sanders) wrote: Probably because 65536 = 2^16, so the result is 32bit fixed point with 16 bits of fraction, a good useful format for many things such as fixed point graphics calculations. E.g., if 1.0 is one inch, then you have a range of 32768.0 to 32767.99998474 or so inches in steps of 0.00001525879 inches or so. Even when you square something to do distance calculation, you can deal with up to 181+ inches, which is a pretty large screen. I guess you might have to rescale if you were doing that for one of those mural printers. Another point though: I don't know that the 0.49 makes much sense To see the effect of Round vs Trunc, run the following. Black is Trunc is a bit weird, if you ask me. If that is what Trunc HTH, {$R *.DFM} procedure TForm1.FormPaint(Sender: TObject); end. 