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,start X-Google-Attributes: gid103376,public From: l107353@cliffy.lfwc.lockheed.com (Garlington KE) Subject: Fixed-point question Date: 1995/04/01 Message-ID: <3li7ec$k37@butch.lmsc.lockheed.com>#1/1 X-Deja-AN: 100649478 organization: Lockheed Missiles and Space Co. newsgroups: comp.lang.ada Date: 1995-04-01T00:00:00+00:00 List-Id: There's probably a simple answer to this question, and I'm just too tired to see it, but here goes anyway: We have a user who has defined a fixed-point of the general form type A_Type is delta 0.1 range ...; and some objects like the following: A: constant A_Type := 2.2; B: constant A_Type := 2.3; and an abject C of A_Type which gets set to the expression 9.0 * 0.25. He then runs the following code: if C = A then Text_IO.Put_Line("C equals A"); elsif C = B then Text_IO.Put_Line("C equals B"); else Text_IO.Put_Line("C equals neither!"); end if; and of course it says that C equals neither, since C is stored as the model number 2.25, which is neither 2.1875 nor 2.3125. I explain this to the user, and all is well until he asks: "How should I do this comparison, then?" Thinking back to my old FORTRAN days with floating-point, I say, "Well, you compute the absolute difference between the two numbers, and then see if the difference is less than some epsilon." However, I can't for the life of me decide how to write the equality function such that (1) C will be "equal" to B and (2) C will not be "equal" to A, nor what epsilon is right (A_Type'Small?) If someone could post the "roughly equal" function I'm describing, I would appreciate it. (Note: this would need to be a pre-Ada 95 solution). -------------------------------------------------------------------- Ken Garlington GarlingtonKE@lfwc.lockheed.com F-22 Computer Resources Lockheed Fort Worth Co. If LFWC or the F-22 program has any opinions, they aren't telling me.