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=0.6 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00, HK_RANDOM_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3bd77c432d79dfbc,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!cyclone1.gnilink.net!spamkiller.gnilink.net!gnilink.net!trnddc05.POSTED!20ae255c!not-for-mail Newsgroups: comp.lang.ada From: Justin Gombos Subject: When floating point result intervals span the boundary - what value is selected? User-Agent: slrn/0.9.8.1 (Linux) Message-ID: Date: Fri, 03 Mar 2006 01:30:07 GMT NNTP-Posting-Host: 141.149.87.138 X-Complaints-To: abuse@verizon.net X-Trace: trnddc05 1141349407 141.149.87.138 (Thu, 02 Mar 2006 20:30:07 EST) NNTP-Posting-Date: Thu, 02 Mar 2006 20:30:07 EST Xref: g2news1.google.com comp.lang.ada:3247 Date: 2006-03-03T01:30:07+00:00 List-Id: Question for the language lawyers- Suppose you have the type: type Sine_Type is digits 6 range -1.0..1.0; You perform an operation on two objects of this type, and the mathematical result is exactly 1.0, so the result interval is /partially/ in range. Is there any guarantee that the stored result will be in range? It would be unreasonable for a compiler to select the next highest model number, but it seems the language allows it. The Ada LRM seems to make no guarantees - leaving it up to the compiler (whenever T'Machine_Overflows is false). The GNAT manual doesn't state either way what it does. This code raises some more questions: with Ada.Text_IO; procedure Tiny_Real is type Sine_Type is digits 6 range -1.0..1.0; Oversized : Sine_Type := Sine_Type'Last + Sine_Type'Small; Well_Oversized : constant Float := Float(Sine_Type'Last) + Float(Sine_Type'Small * 500000.0); begin Ada.Text_IO.Put ("The smallest possible float is " & Float'Image(Float'Small)); Ada.Text_IO.New_Line; -- Strangely, the smallest possible float can be reduced even more. -- Could it be that the value is in a register, thus capable of -- representing fractional model number sizes? -- Ada.Text_IO.Put ("A quarter of that is " & Float'Image(Float'Small / 4.0)); Ada.Text_IO.New_Line; -- 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)); Ada.Text_IO.New_Line; Ada.Text_IO.Put ("Oversized is " & Float'Image(Float(Oversized))); -- I was expecting this to throw a constraint error: -- Oversized := Sine_Type(Well_Oversized); Ada.Text_IO.New_Line; Ada.Text_IO.Put ("Oversized is " & Float'Image(Float(Oversized))); end Tiny_Real; The output: The smallest possible float is 2.58494E-26 A quarter of that is 6.46235E-27 Safe_Last is 3.40282E+38 Oversized is 1.00000E+00 Oversized is 1.00000E+00 -- PM instructions: do a C4esar Ciph3r on my address; retain punctuation.