Xref: utzoo comp.lang.misc:3503 comp.arch:11485 Path: utzoo!attcan!uunet!ginosko!gem.mps.ohio-state.edu!rpi!batcomputer!cornell!rochester!pt.cs.cmu.edu!MATHOM.GANDALF.CS.CMU.EDU!lindsay From: lindsay@MATHOM.GANDALF.CS.CMU.EDU (Donald Lindsay) Newsgroups: comp.lang.misc,comp.arch Subject: Numbers (was Re: Fast conversions) Keywords: fixed point integer Message-ID: <6244@pt.cs.cmu.edu> Date: 23 Sep 89 19:55:25 GMT References: <832@dms.UUCP> <688@UALTAVM.BITNET> <9dAz02zs58y201@amdahl.uts.amdahl.com> <27935@winchester.mips.COM> <136@bbxsda.UUCP> <1989Sep22.201906.10618@utzoo.uucp> Organization: Carnegie-Mellon University, CS/RI Lines: 33 >In article <136@bbxsda.UUCP> scott@bbxsda.UUCP (Scott Amspoker) writes: >..some of us need to have 100 pennies == 1 dollar. Interest calculations >carried out to 3 or 4 decimal places need to round correctly. Well, it is possible to have decimal floating point. I myself perpetrated a BCD floating-point package, back in the eight-bit days. The military world has always been fond of putting decimal points in the middle of binary integers, and calling it "fixed point". The worst language I have ever used, the navy's CMS-2M, featured this data type. The spec for Ada required it, so now Ada allows you to say type VOLT is delta 0.125; This actually runs fine on normal machines, because it is the compiler that maintains the scaling (in this case, by three bits). The real problem is that the roundoff will be in eighths of a volt (or 256ths of a penny, or 1024ths of a nautical mile, or whatever). Also, the conversions are bad: voltage := 0.3; -- choice is ,,0.25, 0.375,,, In general, people would be better off if they could say something like type MILLVOLT is integer; type VOLT is MILLIVOLT * 1000; Normal floating point has a dynamic range of 10**76 (or whatever). A 32 bit integer only has a range of 10**9, but IBM takes in more than 10**13 pennies per year. So, a 64 bit integer (10**19) is about right when you want to compute in millicents, and this is what I recommend. -- Don D.C.Lindsay Carnegie Mellon Computer Science