From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,63c3482f0fa7ae08 X-Google-Attributes: gid103376,public From: guerby@gnat.com (Laurent Guerby) Subject: Re: ESP code rewritten in Ada Date: 1996/11/05 Message-ID: #1/1 X-Deja-AN: 194793373 sender: guerby@schonberg.cs.nyu.edu references: <327F5B2B.47E3@lmtas.lmco.com> organization: New York University reply-to: guerby@gnat.com newsgroups: comp.lang.ada Date: 1996-11-05T00:00:00+00:00 List-Id: >-- General-purpose low-pass filter, >-- implementing a first-order lag. >-- Instantiate a copy for each input >-- such that copy has same lifetime >-- as input. >generic > Shift : Positive; > -- Gain is 2 to the negative Shift. > -- E.g., shift => 4 implies gain = 1/16 > -- 2**Shift must fit in max precision > > type Signal is range <>; > -- Signal should be at least Shift+1 > -- bits less than max precision > >package Filter is > function Lag (U : Signal) return Signal; I would add a pragma Inline here, so the generated code may look even more competitive ;-). >end Filter; > >with System; >package body Filter is > > type Long is range > System.Min_Int .. System.Max_Int; This may drag unreasonable arithmetic on a given machine. May be it's better to add a "base" type to the generic formal (type Long is range <>). Or to compute the needed range: type Long is range 0 .. 2 ** Shift; But this may damage compiler optimization. > X : Long := 0; > > function Lag (U : Signal) return Signal is > D : constant Long := Long(2**Shift); > begin > X := X + Long(U) - X / D; > return Signal (X / D); > end Lag; > >end Filter; -- Laurent Guerby , Team Ada. "Use the Source, Luke. The Source will be with you, always (GPL)."