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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.ecp.fr!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: RFC: Generic Fixed-Point IIR Filter Date: Thu, 26 Mar 2015 15:34:21 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <2c2ee86e-b9bd-49e3-aa7f-206f3c4da95e@googlegroups.com> NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1427402061 2622 24.196.82.226 (26 Mar 2015 20:34:21 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 26 Mar 2015 20:34:21 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: number.nntp.giganews.com comp.lang.ada:192576 Date: 2015-03-26T15:34:21-05:00 List-Id: "Patrick Noffke" wrote in message news:2c2ee86e-b9bd-49e3-aa7f-206f3c4da95e@googlegroups.com... ... > 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? There's probably not a single implementation; the implementation likely depends on the smalls and ranges of the input types and the output (converting) type. (There has to be a convert-to type, universal fixed can never stand alone.) In particular, in simple cases (where there is a clear relationship between the small values such that scaling is an integer operation), probably a 32-bit or 64-bit integer operation would be used. In cases that aren't so simple, who knows? Janus/Ada falls back on floating point in that case, because what do you do if the small of one input type is 0.3141596 and the other is 0.0025, and the small of the output is 0.0001? Hopefully, such things don't occur in code written by people that know what they're doing, but it's possible and the compiler has to somehow generate code for it. At least the floating point temporaries have lots of bits available, so you're probably going to get the right answer if possible. Anyway, you're better off reasoning from principles. Universal fixed is not supposed to overflow (it doesn't have a constraint), so I would expect some sort of 64-bit implementation ultimately. 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 ". 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! Randy. Randy.