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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.236.74 with SMTP id us10mr17947367pac.28.1427404888540; Thu, 26 Mar 2015 14:21:28 -0700 (PDT) X-Received: by 10.182.142.230 with SMTP id rz6mr174786obb.29.1427404658289; Thu, 26 Mar 2015 14:17:38 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!z20no2711igj.0!news-out.google.com!q14ni0ign.0!nntp.google.com!z20no2709igj.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 26 Mar 2015 14:17:38 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=74.203.194.21; posting-account=bXcJoAoAAAAWI5APBG37o4XwnD4kTuQQ NNTP-Posting-Host: 74.203.194.21 References: <2c2ee86e-b9bd-49e3-aa7f-206f3c4da95e@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4cc649b0-58be-4919-a203-ae9dafbc361c@googlegroups.com> Subject: Re: RFC: Generic Fixed-Point IIR Filter From: Patrick Noffke Injection-Date: Thu, 26 Mar 2015 21:21:28 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:25275 Date: 2015-03-26T14:17:38-07:00 List-Id: On Thursday, March 26, 2015 at 3:34:23 PM UTC-5, Randy Brukardt wrote: > "Patrick Noffke" wrote in message > ... > > How is universal_fixed (likely) implemented on a 32-bit processor? > > What happens if you multiply two fixed-point types that use all 32-bits > > for range and precision? What if one type uses all the bits for the range > > and another uses all the bits for precision? > > Note that this is wrong: > > >It is therefore sometimes possible to avoid the 2nd type if all > >calculations > >can be done in a single expression which yields a value that fits in the > >smaller type, despite having intermediate results which do not. > > A result of universal-fixed always has to be converted immediately to > another type. It's not legal to use it directly. Specifically, 4.5.5(19.1/2) > says: "The above two fixed-fixed multiplying operators shall not be used in > a context where the expected type for the result is itself universal_fixed > ". > When I try to compute a 2nd order filter result as: Filter.Y (1) := (Filter.B (1) * Filter.X (1) + Filter.B (2) * Filter.X (2) + Filter.B (3) * Filter.X (3) - Filter.A (2) * Filter.Y (2) - Filter.A (3) * Filter.Y (3)) / Filter.A (1); I get this error: iir_filter.adb:46:60: ambiguous universal_fixed_expression iir_filter.adb:46:60: possible interpretation as type "Standard.Duration" iir_filter.adb:46:60: possible interpretation as type "Fixed_Type" defined at iir_filter.ads:3 I don't really understand the clause in 4.5.5(19.1/2). What defines the context? I think it's clear in my statement the "expected type for the result" is Fixed_Type, so why is Jeffrey's statement wrong? And then how do I get past this error? Is the problem with the + operator? How do I remove the ambiguity? > That's so the compiler can always know how many bits are needed for the > intermediate results (in order to avoid overflow). But you'll need to figure > those out yourself (and as you noted, you can't declare them inside of the > generic). > > There's a reason that fixed point is rarely used! > My processor doesn't have an FPU. Patrick