From: Martin <martin.dowie@btopenworld.com>
Subject: Re: Saturation arithmetic woes.
Date: Wed, 29 Jul 2009 10:13:48 -0700 (PDT)
Date: 2009-07-29T10:13:48-07:00 [thread overview]
Message-ID: <b461ebbe-809e-44b6-9ccd-a38a90d1f7a6@c29g2000yqd.googlegroups.com> (raw)
In-Reply-To: 1a16b458-0201-4320-9787-2836ed58f991@e27g2000yqm.googlegroups.com
On Jul 29, 6:03 pm, xorque <xorquew...@googlemail.com> wrote:
> generic
> type Discrete_Type is (<>);
>
> package Saturation is
>
> type Saturated_Type is new Discrete_Type;
>
> function "+"
> (Left : Saturated_Type;
> Right : Saturated_Type) return Saturated_Type;
>
> end Saturation;
>
> package body Saturation is
>
> function "+"
> (Left : Saturated_Type;
> Right : Saturated_Type) return Saturated_Type
> is
> Temp_Left : constant Discrete_Type := Discrete_Type (Left);
> Temp_Right : constant Discrete_Type := Discrete_Type (Right);
> begin
> if Temp_Left + Temp_Right > Discrete_Type'Last then
> return Saturated_Type (Discrete_Type'Last);
> end if;
> if Temp_Left + Temp_Right < Discrete_Type'First then
> return Saturated_Type (Discrete_Type'First);
> end if;
>
> return Saturated_Type (Temp_Left + Temp_Right);
> end "+";
>
> end Saturation;
>
> with Saturation;
> with Ada.Text_IO;
>
> procedure Main is
> type T is range 1 .. 10;
>
> package T_Saturated is new Saturation (T);
> package IO renames Ada.Text_IO;
> package TIO is new Ada.Text_IO.Integer_IO
> (T_Saturated.Saturated_Type);
>
> use type T_Saturated.Saturated_Type;
>
> X : constant T_Saturated.Saturated_Type := 5;
> Y : constant T_Saturated.Saturated_Type := 9;
> begin
> TIO.Put (X + Y); -- 10
> IO.New_Line;
> end Main;
>
> saturation.adb:10:18: there is no applicable operator "+" for type
> "Discrete_Type" defined at saturation.ads:2
> saturation.adb:13:18: there is no applicable operator "+" for type
> "Discrete_Type" defined at saturation.ads:2
> saturation.adb:17:38: there is no applicable operator "+" for type
> "Discrete_Type" defined at saturation.ads:2
>
> I'm afraid I'm not well versed in the rules regarding operator name
> resolution...
generic
type Discrete_Type is (<>);
with function "+" (L, R : Discrete_Type) return Discrete_Type is <>;
package Saturation is
You need to provide a suitable "+" operator.
Cheers
-- Martin
next prev parent reply other threads:[~2009-07-29 17:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-29 17:03 Saturation arithmetic woes xorque
2009-07-29 17:13 ` Martin [this message]
2009-07-29 18:14 ` Jeffrey R. Carter
2009-07-29 19:14 ` Niklas Holsti
2009-07-29 19:39 ` xorque
2009-07-30 9:09 ` Jean-Pierre Rosen
2009-07-30 11:51 ` Martin
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox