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,7fd5a5da28dace78 X-Google-Attributes: gid103376,public From: matthew_heaney@acm.org (Matthew Heaney) Subject: Re: Renaming Fixed Point Mutiplicative operator in Ada 95 Date: 1998/05/19 Message-ID: #1/1 X-Deja-AN: 354859300 Content-Transfer-Encoding: 8bit References: <3561F32B.2F0B@innotts.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Organization: Network Intensive Newsgroups: comp.lang.ada Date: 1998-05-19T00:00:00+00:00 List-Id: In article <3561F32B.2F0B@innotts.co.uk>, Stuart Hutchesson wrote: (start of quote) In certain applications (notably safety critical systems) it is good practise to supply protected maths operators (guarding against overflow etc). In these applications the use of floating point is sometimes frowned upon also and a common solution is to use fixed point types and override/rename the mathematical operations. (end of quote) I agree that you should use fixed point when it makes sense (you have absolute - not relative - error). But why would you want to override (or otherwise hide) the primitive operators of the fixed point type? Furthermore, how can you? Any fixed point type can be multiplied by any other fixed point type, for example type T1 is delta 0.1 range 0.0 .. 10.0; type T2 is delta 0.2 range 2.0 .. 200.0; type T3 is delta 3.0 range 0.0 .. 3000.0; declare O1 : T1 := 1.3; O2 : T2 := 3.8; O3 : T3 := O1 * O2; begin is perfectly legal. How can you anticipate all the fixed point types that you'll multiply with objects of type NewFixed? And besides, fixed point operations deliver an _exact_ result. How do you even get an overflow exception multiplying fixed point numbers? The result of a fixed point multiply is of type universal fixed. Doesn't universal fixed already have infinate precision? You mean you need bigger than infinity to do a multiply? Solving some graph problems, perhaps? Or maybe a tiling problem? (start of quote) package Test1 is type NewFixed is delta 0.01 range -1000.0 .. +1000.0; (end of quote) Why didn't you specify a 'Small for the type? You realize of course that type NewFixed does _not_ have a small equal to 0.01 - it's some power of 2 less than 0.01. (start of quote) function MultFixed (LEFT : NewFixed; RIGHT : NewFixed) return NewFixed ; (end of quote) This is a very misguided thing to do. Please, do not do this. (start of quote) function "*" (LEFT : NewFixed ; RIGHT : NewFixed ) return NewFixed renames Test1.MultFixed ; A1, A2, A3 : NewFixed; function MultFixed (LEFT : NewFixed; RIGHT : NewFixed) return NewFixed is begin return 0.0; end MultFixed; procedure Test1DoIt is begin A1 := A2 * A3; end Test1DoIt; end Test1; However this is thrown out by ObjectAda saying the line A1 := A2*A3 is ambiguous - it appears to match the context for the universal_fixed multipication operator as well as the renamed operator. (end of quote) That's because both operations are directly visible: you're renaming declaring, and the primitive operation for the type. Just like the compiler is telling you. (start of quote) Anyone know if this this a compiler bug or a correct interpretation of the Ada95 LRM?? If it is the latter then it seems to rule Ada95 out for systems that need to provide protected fixed point maths. (end of quote) I think you need to learn more about fixed point math. Please, don't override primitive operations of a fixed point type. No, you don't need "protected" fixed point math. The features you want are already built into Ada's fixed point model. See RM95 4.5.5.