Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!apple!netcom!rodent From: rodent@netcom.COM (Ben Discoe) Newsgroups: comp.sys.amiga.programmer Subject: Switching between integer and floating point Message-ID: <1991Apr24.041205.1588@netcom.COM> Date: 24 Apr 91 04:12:05 GMT Organization: Netcom - Online Communication Services UNIX System {408 241-9760 guest} Lines: 39 I've been working on a 3D object viewer intended for PD release, with source, as soon as it's stable. My problem is this: when the project was started, I only had a 1000 to work on, so I wrote all the math using two kinds of fixed-point integer math (one kind for angles, another for coordinates). Now I (and many people who may want the code) are on accelerated systems with 6888x's, so I'd like to include a compile-time flag to compile with floating-point math instead of the integers. I'm sure many other people have faced this same problem: how do you keep one source with two different kinds of math involved? There are three options I can think of, and none are appealing. 1. use a lot of #defines: #if INTEGER #define mult(a, b) ((a*b)>>8) #else #define mult(a, b) (a*b) #endif This makes code very ugly and hard to understand/debug. 2. Use C++. I'm not positive, but it seems likely that you could introduce a fixed-point integer class that would know how to operate on itself and other classes. This would allow us to keep one, elegant C-like source, but would limit the number of people who could make use of the source, and make it less portable (since you'd have to find a C++ compiler on the machines you want to take it to). 3. Maintain two seperate sources. This has great potential for confusion unless you are extremely careful to keep the sources functionally identical. Since the fixed-point integer is full of shift-operations, it bears only a little resembleance to the floating point code, making things difficult. Does anyone have other ideas or comments about these approaches? ---------------- Ben in San Jose, an Amigoid in a non-Amiga city.