* choice of fixed point type
@ 2000-03-01 0:00 tmoran
2000-03-03 0:00 ` tmoran
0 siblings, 1 reply; 7+ messages in thread
From: tmoran @ 2000-03-01 0:00 UTC (permalink / raw)
Why does
type duration is delta 1.0E-13 range 0.0 .. 0.000_1;
f : float;
i : integer := 10_000;
begin
f := float(0.000_0001/i);
ada.text_io.put_line(float'image(f));
f := float(duration'(0.000_0001)/i);
ada.text_io.put_line(float'image(f));
f := 0.000_0001/float(i);
ada.text_io.put_line(float'image(f));
print
0.00000E+00
9.94760E-12
1.00000E-11
Is <universal real> / <integer> always treated as a call on
function "/"(Left : Standard.Duration; Right : Integer)
return Standard.Duration; ?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: choice of fixed point type
2000-03-01 0:00 choice of fixed point type tmoran
@ 2000-03-03 0:00 ` tmoran
2000-03-04 0:00 ` Richard D Riehle
0 siblings, 1 reply; 7+ messages in thread
From: tmoran @ 2000-03-03 0:00 UTC (permalink / raw)
I asked:
> Is <universal real> / <integer> always treated as a call on
>function "/"(Left : Standard.Duration; Right : Integer)
>return Standard.Duration; ?
It turns out that was merely a problem with a single compiler.
Three out of four compilers said the division was ambiguous.
But, in the absence of any other fixed point types, Ada accepts
Long_Float_Functions.Cos(Long_Float(Ada.Numerics.Pi/integer(i)))
and calculates pi/i as type Duration, then converts that to
a Long_Float and then takes the cosine. That typically means
the argument is not nearly as accurate as the person using
Long_Float would expect, and of course neither is the resulting cos.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: choice of fixed point type
2000-03-03 0:00 ` tmoran
@ 2000-03-04 0:00 ` Richard D Riehle
2000-03-05 0:00 ` tmoran
0 siblings, 1 reply; 7+ messages in thread
From: Richard D Riehle @ 2000-03-04 0:00 UTC (permalink / raw)
In article <9vTv4.603$zz5.39941@news.pacbell.net>,
tmoran@bix.com wrote:
>I asked:
>> Is <universal real> / <integer> always treated as a call on
>>function "/"(Left : Standard.Duration; Right : Integer)
>>return Standard.Duration; ?
> It turns out that was merely a problem with a single compiler.
>Three out of four compilers said the division was ambiguous.
Keeping us in suspense, Tom? Which three gave you the good information? Which
one got it wrong? Eager minds want to know. :-)
Richard Riehle
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: choice of fixed point type
2000-03-04 0:00 ` Richard D Riehle
@ 2000-03-05 0:00 ` tmoran
2000-03-06 0:00 ` Robert Dewar
0 siblings, 1 reply; 7+ messages in thread
From: tmoran @ 2000-03-05 0:00 UTC (permalink / raw)
>Keeping us in suspense, Tom? Which three gave you the good information? Which
>one got it wrong? Eager minds want to know. :-)
Given:
with Ada.Text_Io;
procedure test is
type duration is delta 1.0 range 0.0 .. 60.0;
f : float;
i : integer := 3;
begin
f := float(16.0/i);
ada.text_io.put_line(float'image(f));
end test;
Gnat 3.12p NT gave no error message and used, apparently,
Standard.Duration
ObjectAda 7.1.2.205 said
--------------------Target: Win32 (Intel) Debug--------------------
test.adb: Error: line 10 col 18 LRM:8.6(31), Expression is ambiguous when interpreted as an expression of any, Returning first interpretation
test.adb: Error: line 10 col 8 The expression is ambiguous, Continuing
Front end of ..\examples\test.adb failed with 2 errors.
Tool execution failed.
"David W. Glessner" <dwglessn@collins.rockwell.com> tells me:
Sure 'nuff, Rational Apex 3.0.0b doesn't compile your program.
08:55:32 >>> Line 7: F := Float (0.000_0001 / I);
08:55:32 *** 0.000_0001 / I is ambiguous
08:55:32 *** "/" could be (in TEST_FIXED_DURATION)
Test_Fixed_Duration.Duration."/"
08:55:32 *** "/" could be (in STANDARD) "/"
Janus 3.1.1e NT said:
In File F:\test.ada at line 10
--------------
9: begin
10: f := float(16.0/i);
-------------------------^
*ERROR* Unable to resolve expression (6.4.6) [RM 5.2(4)]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: choice of fixed point type
2000-03-05 0:00 ` tmoran
@ 2000-03-06 0:00 ` Robert Dewar
2000-03-06 0:00 ` David W. Glessner
0 siblings, 1 reply; 7+ messages in thread
From: Robert Dewar @ 2000-03-06 0:00 UTC (permalink / raw)
In article <S_iw4.2837$im1.54677@news.pacbell.net>,
tmoran@bix.com wrote:
> Gnat 3.12p NT gave no error message and used, apparently,
> Standard.Duration
As one would expect, since this type is most certainly
visible. However, if a compiler has other fixed point types
visible (certainly permissible), then it would be ambiguous.
The code in question is really non-portable at best, wrong
at worst, but not illegal if there is only one fixed-point
type visible. At least that's my reading.
Sent via Deja.com http://www.deja.com/
Before you buy.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: choice of fixed point type
2000-03-06 0:00 ` Robert Dewar
@ 2000-03-06 0:00 ` David W. Glessner
2000-03-06 0:00 ` tmoran
0 siblings, 1 reply; 7+ messages in thread
From: David W. Glessner @ 2000-03-06 0:00 UTC (permalink / raw)
In article <89v3nq$rs7$1@nnrp1.deja.com>,
Robert Dewar <robert_dewar@my-deja.com> wrote:
> In article <S_iw4.2837$im1.54677@news.pacbell.net>,
> tmoran@bix.com wrote:
>
> > Gnat 3.12p NT gave no error message and used, apparently,
> > Standard.Duration
>
> As one would expect, since this type is most certainly
> visible. However, if a compiler has other fixed point types
> visible (certainly permissible), then it would be ambiguous.
> The code in question is really non-portable at best, wrong
> at worst, but not illegal if there is only one fixed-point
> type visible. At least that's my reading.
But doesn't Tom's example have two fixed-point types visible?
Namely, Standard.Duration, and Test.Duration.
(I thought GNAT 3.12p compiled, without warning, the example
even when "type Duration is delta ..." was replaced with
"type T is delta ...". I don't have access to 3.12p right
now, so I can't verify that.)
--
David
Sent via Deja.com http://www.deja.com/
Before you buy.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: choice of fixed point type
2000-03-06 0:00 ` David W. Glessner
@ 2000-03-06 0:00 ` tmoran
0 siblings, 0 replies; 7+ messages in thread
From: tmoran @ 2000-03-06 0:00 UTC (permalink / raw)
>(I thought GNAT 3.12p compiled, without warning, the example
>even when "type Duration is delta ..." was replaced with
>"type T is delta ...". I don't have access to 3.12p right
>now, so I can't verify that.)
Using "type D is delta ..." also fails to generate any warning.
>> The code in question is really non-portable at best, wrong
>> at worst, but not illegal if there is only one fixed-point
>> type visible. At least that's my reading.
The code in question arose from testing around an "Ada
surprise". An execution error had been traced to where a
programmer had written something like
Long_Float(N * Ada.Numerics.pi) instead of
Long_Float(N) * Ada.Numerics.pi
resulting in the use of (relatively imprecise) type Duration
for the multiply instead of Long_Float. Standard.Duration
was of course (silently) visible, and there was no other
fixed point type in this code, so the compiler did what the
programmer said, but not what he wanted.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2000-03-06 0:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-01 0:00 choice of fixed point type tmoran
2000-03-03 0:00 ` tmoran
2000-03-04 0:00 ` Richard D Riehle
2000-03-05 0:00 ` tmoran
2000-03-06 0:00 ` Robert Dewar
2000-03-06 0:00 ` David W. Glessner
2000-03-06 0:00 ` tmoran
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox