From: Justin Gombos <rpbkbq.xax.gld@uluv.kbq>
Subject: When floating point result intervals span the boundary - what value is selected?
Date: Fri, 03 Mar 2006 01:30:07 GMT
Date: 2006-03-03T01:30:07+00:00 [thread overview]
Message-ID: <z_MNf.7928$d61.2481@trnddc05> (raw)
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
<http://www.adaic.org/standards/95lrm/html/RM-G-2-1.html> 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.
next reply other threads:[~2006-03-03 1:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-03 1:30 Justin Gombos [this message]
2006-03-03 2:55 ` When floating point result intervals span the boundary - what value is selected? haley
2006-03-03 5:51 ` Jeffrey R. Carter
2006-03-04 16:46 ` Justin Gombos
2006-03-05 19:12 ` Jeff Carter
2006-03-05 19:13 ` Jeff Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox