From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Dimensions and fixed point types
Date: Wed, 09 Jun 2004 13:04:01 -0400
Date: 2004-06-09T13:04:01-04:00 [thread overview]
Message-ID: <hfSdnb_y5tGc3lrdRVn_iw@comcast.com> (raw)
In-Reply-To: <40c6bf5c_1@baen1673807.greenlnk.net>
Martin Dowie wrote:
> "Duncan Sands" <baldrick@free.fr> wrote in message
> news:mailman.77.1086765132.391.comp.lang.ada@ada-france.org...
>
>>Fixed point types have a remarkable property:
>>you can multiply any two of them to get a third.
>>You can multiply apples and oranges and get
>>bananas. This goes against type safety.
I agree, and I objected to the original Ada95 rule that allowed the
explict type conversion from universal fixed to be omitted. In addition
to the problems created when you do want to explicitly define a multiply
operation, it creates the serious problem Duncan refers to:
>> Suppose I have several fixed point types, for
>> example
>>
>> type Price is delta 0.01 digits ...;
>> type Volume is delta 1.0 digits ...;
>> type Value is delta 0.01 digits ...;
P: Price; V: Volume; Val: Value;
...
P := V * Val; -- the compiler won't object!
> I think this is being addressed by the ARG in AI-364
>
> http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00364.TXT?rev=1.6
>
> Still a work item though...
What is being worked on is actually different problem, where you do want
to declare your own multiplication or division operators, and find that
they can't be called in infix notation.
That having been said, the current version exactly fixes Duncan Sands
problem. According to the new draft, if you declare a multiplication
operation for Apples, all of the "special" Apple * fixed and fixed *
Apple operations returning universal_fixed will be hidden where the user
defined operators are visible.
So to go back to Duncan's original complaint add:
function "*"(Left: Price; Right: Volume) return Value;
This will hide ALL the predefined operations that Duncan wants to get
rid of, and any new ones that involve Price, Volume, or Value, so the line:
P := V * Val; -- The compiler will complain that no visible "*" matches.
Glad to be of service. ;-)
--
Robert I. Eachus
"The terrorists rejoice in the killing of the innocent, and have
promised similar violence against Americans, against all free peoples,
and against any Muslims who reject their ideology of murder. Their
barbarism cannot be appeased, and their hatred cannot be satisfied.
There's only one way to deal with terror: We must confront the enemy and
stay on the offensive until these killers are defeated." -- George W. Bush
next prev parent reply other threads:[~2004-06-09 17:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-09 7:11 Dimensions and fixed point types Duncan Sands
2004-06-09 7:47 ` Martin Dowie
2004-06-09 17:04 ` Robert I. Eachus [this message]
2004-06-11 7:16 ` Duncan Sands
2004-06-11 7:12 ` Duncan Sands
2004-06-11 7:26 ` Hyman Rosen
2004-06-11 7:46 ` Duncan Sands
2004-06-11 17:47 ` Hyman Rosen
2004-06-11 19:10 ` Duncan Sands
2004-06-12 3:40 ` Robert I. Eachus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox