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: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.etla.org!feeder.erje.net!2.us.feeder.erje.net!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!buffer1.nntp.dca1.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 15 Aug 2017 13:11:56 -0500 Newsgroups: comp.lang.ada Subject: Re: 32-bit float and 64-bit float From: csampson@inetworld.net (Charles H. Sampson) Date: Tue, 15 Aug 2017 11:11:56 -0700 Message-ID: <1naspc7.17e30f01qpxt22N%csampson@inetworld.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: MacSOUP/2.8.3 (Mac OS X version 10.5.8 (PPC)) X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-se393VK/r7Fb0oMB/kTBnGW7tW6Zx+zcfS7mDrAyOtxmUBHCg82KHrDaMMsPVFmUK76oyi0DFA+OEs1!w0TmhlV2788q/7v28ruoqai03+0QoiH8sAOqU3/WcjpTClNv4ZVCPoeoPeWPZyB8hq+Hj/2FXBSu!NA== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3417 Xref: news.eternal-september.org comp.lang.ada:47727 Date: 2017-08-15T11:11:56-07:00 List-Id: Victor Porton wrote: > Dmitry A. Kazakov wrote: > > > On 14/08/2017 00:29, Victor Porton wrote: > >> What is the best way to define in Ada types which are expected to > >> contain: > >> > >> 1. 64-bit floating point numbers (incl. ±Inf, ±0, NaN); > >> > >> 2. 32-bit floating point numbers (incl. ±Inf, ±0, NaN). > > > > There is no way since you specified neither the precision and range nor > > the floating-point representation format IEEE 754, IBM, DEC etc. > > > > Ada's way is the former. The latter is not possible in general. > > > > If you have a requirement to support a specific representation, e.g. for > > I/O you have to convert it forth and back to an Ada type most close to > > it. In Simple Components there are packages to convert IEEE 754 floats: > > > > http://www.dmitry-kazakov.de/ada/components.htm#IEEE_754 > > I understand this. > > My question was how to do it in the "best" (not "perfect") way. > > I think Float and Long_Float will do the job on most compilers and machines. > But maybe I should instead use "digits" in Ada? If yes, then how many > digits? Yes, this is the "right" way. The Ada way is to specify the (numerical) attributes to do your job and let the compiler worry about choosing the representation that accomplishes this. In the case of floating-point (real) the specification is in terms of number of specific digits and range. If you're working on a machine that supports IEEE 754 you'll get the odd values. The infinities can be a significant pain in the posterior if there's any chance you'll be near extreme values. For this reason, you should always do a mathematical analysis of your application and use the Range specification. A good compiler will then keep you away from the infinities. Nans can pop up at really inconvenient times. If there's a possibility that they might, heroic action is required. The compiler should take care of +0 and -0 issues. Charlie -- Nobody in this country got rich on his own. You built a factory--good. But you moved your goods on roads we all paid for. You hired workers we all paid to educate. So keep a big hunk of the money from your factory. But take a hunk and pay it forward. Elizabeth Warren (paraphrased)