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: buffer1.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Brian Drummond Newsgroups: comp.lang.ada Subject: Re: Fixed-point question Date: Sun, 28 Jun 2015 11:39:56 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <249bcd57-3074-4566-b8f2-03e6923bfbce@googlegroups.com> <6a104bde-67ea-48a5-a035-6be3f9235d42@googlegroups.com> <21e4185b-bc89-4940-b329-09863ad17344@googlegroups.com> <0320a865-5636-4ac6-81f7-ea56b761ce0d@googlegroups.com> <87a8vlrm9j.fsf@theworld.com> <876168sx28.fsf@theworld.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sun, 28 Jun 2015 11:39:56 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="da745e888d4a5182b5fda6212bbb0a63"; logging-data="15661"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/G+i+NwrGjQ3pVQ3eLN1BfNn7Lc679fOk=" User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Cancel-Lock: sha1:TAw1A24L3XHZGJWra6E2/vNcIIA= Xref: number.nntp.giganews.com comp.lang.ada:193814 Date: 2015-06-28T11:39:56+00:00 List-Id: On Sat, 27 Jun 2015 16:42:07 -0400, Bob Duff wrote: > There's a rule somewhere that says the context has to provide the type > of the result, so the compiler knows how much precision is needed. E.g. > you can say "X := Y * Z;" but not "X := Y * Z * W;". A rule that surprised me when I first ran into it, but on a moment's reflection as a hardware guy, makes perfect sense. It forces you to specify the range and resolution of intermediate results, eliminating rounding and overflow surprises. Once I rewrote an algorithm along the lines imposed by this rule, I could make it generic and instantiate it with any fixed or floating point type I wanted, to investigate its stability and accuracy (with the eventual intent of translating to a VHDL implementation using minimal hardware). -- Brian