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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3bd77c432d79dfbc X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: When floating point result intervals span the boundary - what value is selected? References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Fri, 03 Mar 2006 05:51:47 GMT NNTP-Posting-Host: 67.150.73.31 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.news.pas.earthlink.net 1141365107 67.150.73.31 (Thu, 02 Mar 2006 21:51:47 PST) NNTP-Posting-Date: Thu, 02 Mar 2006 21:51:47 PST Xref: g2news1.google.com comp.lang.ada:3250 Date: 2006-03-03T05:51:47+00:00 List-Id: Justin Gombos wrote: > Question for the language lawyers- > > Suppose you have the type: > > type Sine_Type is digits 6 range -1.0..1.0; You need to remember the distinction between a type and a subtype. The name in a type declaration is the first-named subtype. Your declaration is equivalent to type Sine_Type'Base is digits X; subtype Sine_Type is Sine_Type'Base range -1.0 .. 1.0; where X >= 6. Sine_Type'Base is an unconstrained floating-point type that makes sense for your hardware. > Oversized : Sine_Type := Sine_Type'Last + Sine_Type'Small; This is odd; 'Small is defined only for fixed-point types (ARM K). Maybe this is compiler specific. You should probably use 'Model_Small. Anyway, since 'Small gives 2.58494E-26 and you probably have 6 digits of accuracy, 1.0 + 'Small = 1.0. Remember that "+" is defined for the base type. > Well_Oversized : constant Float := Float(Sine_Type'Last) + > Float(Sine_Type'Small * 500000.0); Similarly here, 5.0E5 * 2.58494E-26 ~ 1.3E-20, and 1.0 + 1.3E-20 = 1.0 with 6 digits of accuracy. > -- I was expecting this to report a model number close to 1.0, not > 3.40282E+38. -- > Ada.Text_IO.Put ("Safe_Last is " & > Float'Image(Sine_Type'Safe_Last)); For a subtype S of a floating-point type T, S'Safe_Last "Yields the upper bound of the safe range of T." (ARM G.2.2). In your case, T is Sine_Type'Base, and its upper bound is much larger than 1.0. > Oversized := Sine_Type(Well_Oversized); Since Well_Oversized is 1.0, there's no problem here. Even if you had a floating point type with enough digits to represent 1.0 + 1.3E-20 as different from 1.0, the conversion to Sine_Type'Base would result in a value of 1.0. -- Jeff Carter "You cheesy lot of second-hand electric donkey-bottom biters." Monty Python & the Holy Grail 14