From: Patrick Noffke <patrick.noffke@gmail.com>
Subject: Re: RFC: Generic Fixed-Point IIR Filter
Date: Thu, 26 Mar 2015 14:17:38 -0700 (PDT)
Date: 2015-03-26T14:17:38-07:00 [thread overview]
Message-ID: <4cc649b0-58be-4919-a203-ae9dafbc361c@googlegroups.com> (raw)
In-Reply-To: <mf1qgd$2hu$1@loke.gir.dk>
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
next prev parent reply other threads:[~2015-03-26 21:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-26 16:25 RFC: Generic Fixed-Point IIR Filter Patrick Noffke
2015-03-26 17:05 ` Dmitry A. Kazakov
2015-03-26 17:41 ` Jeffrey Carter
2015-03-26 19:44 ` Patrick Noffke
2015-03-26 20:34 ` Randy Brukardt
2015-03-26 20:39 ` Jeffrey Carter
2015-03-26 21:12 ` Randy Brukardt
2015-03-26 21:30 ` Patrick Noffke
2015-03-26 22:02 ` Jeffrey Carter
2015-03-27 12:17 ` G.B.
2015-03-26 21:17 ` Patrick Noffke [this message]
2015-03-26 20:37 ` Jeffrey Carter
2015-03-27 11:37 ` Brian Drummond
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox