From: "Jeffrey R. Carter" <spam@spam.com>
Subject: Re: When floating point result intervals span the boundary - what value is selected?
Date: Fri, 03 Mar 2006 05:51:47 GMT
Date: 2006-03-03T05:51:47+00:00 [thread overview]
Message-ID: <TPQNf.1393$Bj7.1143@newsread2.news.pas.earthlink.net> (raw)
In-Reply-To: <z_MNf.7928$d61.2481@trnddc05>
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
next prev parent reply other threads:[~2006-03-03 5:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-03 1:30 When floating point result intervals span the boundary - what value is selected? Justin Gombos
2006-03-03 2:55 ` haley
2006-03-03 5:51 ` Jeffrey R. Carter [this message]
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