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,e1d73eeed8d5628e,start X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Fixed Point Range Date: 1997/10/25 Message-ID: #1/1 X-Deja-AN: 285091038 Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-10-25T00:00:00+00:00 List-Id: A fixed point type declaration introduces a type and a first named subtype. According to the RM (or, at least my reading of the RM), the range for the first subtype is chosen as the value closer to zero of, the corresponding value of the base range, or, the value of the expression implicitly converted to the type. Consider this type: type Fixed is delta 1.0 range 0.0 .. 256.0; for Fixed'Small use 1.0; In the code example below, I print out the values of Fixed'Last and Fixed'Base'Last. The output is: T'Size: 8 T'Base'Size: 16 T'First: 0.0 T'Last: 255.0 T'Base'First: -32768.0 T'Base'Last: 32767.0 My question is this. I interpret the RM to mean that Fixed'Last is the smaller of 256.0 (the expression specified the type declaration) and 32767.0 (the value of Fixed'Base'Last). Yet the value of Fixed'Last is 255.0. Why? The RM says that the expression for the upper bound is "implicitly converted" to the type. Does this mean that the value of the expression 256.0 can be implicitly converted to the value 255.0? I would understand if the base range were -256.0 .. 255.0, then the value of Fixed'Last would make sense. Yet, the output is telling me the base range is much larger than that, so why isn't the value 256.0 used as Fixed'Last? Or perhaps I printed out the value of the base range incorrectly. Is there a preferred method to Fixed'Base'Image (Fixed'Base'Last)? Maybe the base range really is -256.0 .. 255.0, and just my output is bad. -- STX with Ada.Text_IO; use Ada.Text_IO; procedure Test_Fixed is type Fixed is delta 1.0 range 0.0 .. 256.0; for Fixed'Small use 1.0; begin Put ("T'Size: "); Put (Integer'Image (Fixed'Size)); New_Line; PUt ("T'Base'Size: "); Put (Integer'Image (Fixed'Base'Size)); New_Line (2); Put ("T'First: "); Put (Fixed'Image (Fixed'First)); New_Line; Put ("T'Last: "); Put (Fixed'Image (Fixed'Last)); New_Line (2); Put ("T'Base'First: "); Put (Fixed'Base'Image (Fixed'Base'First)); New_Line; Put ("T'Base'Last: "); Put (Fixed'Base'Image (Fixed'Base'Last)); New_Line (2); end; --ETX -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271