From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8e0fcf9e7d370ccc X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Fixed-point question Date: 1995/04/07 Message-ID: #1/1 X-Deja-AN: 100070422 references: <3li7ec$k37@butch.lmsc.lockheed.com> organization: The Mitre Corp., Bedford, MA. newsgroups: comp.lang.ada Date: 1995-04-07T00:00:00+00:00 List-Id: In article <3m43ot$grt@butch.lmsc.lockheed.com> l107353@cliffy.lfwc.lockheed.com (Garlington KE) writes: > Robert Dewar (dewar@cs.nyu.edu) wrote: > : On most modern machines floating-point is much faster than fixed-point in > : any case. Was there really a good case for using fixed-point in this cas. I beg to differ with Professor Dewar on this. Especially when 32-bit fixed point can be used in preference to 64-bit floating point, the costs of the added memory accesses dominates... But even when it is 32-bits vs. 32-bits, the added costs on processors like the Pentium can tip the scales. However, if you need to do multiplies and divides on some RISC chips, especially older SPARC implementations, the lack of support for integer multiply and divide dominates. > I've received a couple of replies concerning a "roughly equal" function, > and I think everyone so far ran up against the same snags I did. I haven't > had time to do any more work on this, but if I do, I'll post the results in > case anyone's interested. There is no need of a "roughly equal" function with fixed point. Numbers are either equal or they differ by 'SMALL or greater in both Ada 83 and Ada 95. > To repeat the problem: A user declared a fixed-point type, like > type D is delta 0.1 range ... Without a clause defining D'SMALL, D'SMALL is 1/16 (0.0625). > This generates a set of model numbers M. In this particular user's mind, > however, he is thinking in terms of the set S = { ... 2.0, 2.1, 2.2 ... } > (is there a name in Ada for this set?). The default display values? (As far as I know there is no name for the value set in the programmer's mind. There might be a name for the values produced by Text_IO.Fixed_IO.Put.) The value set {... 2.0, 2.0625, 2.125, 2.1875, ...} is called the model numbers, and is required to be identical--with the possible exception of one value at each end if the specified limits are not model mnumbers--on all compilers. (The value set for the base type, however, may vary widely in range from machine to machine or compiler to compiler.) > What happened was that he did a calculation that yielded the model > number 2.25, which is neither the model number used by the compiler > for the literal 2.2 nor the model number for the literal 2.3. What > the user wants is a way to map items in M to S, such that the model > number for "2.1" will be equal to 2.1, and both 2.25 and the model > number for "2.3" will be equal to "2.3". This "roughly equal" > function would, ideally, be insensitve to the order of the > operands. Yes, 2.25 is a model number, as is 2.3125... The fix of course is to either use Ada 95 decimal types, or a size clause which sets D'SMALL to 0.1. > If all else fails, I could ask Tartan: their AdaScope debugger does this > mapping, such that when X = 2.25, asking the debugger to print out X yields > the value "2.3". (This also helped to confuse the user; his code was > operating as if X /= 2.3, but the debugger told him X was 2.3!) Uh, if they don't support size clauses for 'SMALL, or Ada 95 decimal types you have a problem. You can use Get and Put on a String to insure what you want, but it will be slow... -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...