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.36.19.2 with SMTP id 2mr6057338itz.4.1516841022029; Wed, 24 Jan 2018 16:43:42 -0800 (PST) X-Received: by 10.157.32.68 with SMTP id n62mr765666ota.6.1516841021921; Wed, 24 Jan 2018 16:43:41 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!paganini.bofh.team!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!g80no313220itg.0!news-out.google.com!s63ni4473itb.0!nntp.google.com!w142no313961ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 24 Jan 2018 16:43:41 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:191:8303:2100:7466:f44c:da21:40b1; posting-account=fdRd8woAAADTIlxCu9FgvDrUK4wPzvy3 NNTP-Posting-Host: 2601:191:8303:2100:7466:f44c:da21:40b1 References: <942235344.537649945.074508.laguest-archeia.com@nntp.aioe.org> <288039467.538377555.666858.laguest-archeia.com@nntp.aioe.org> <62033550-4044-450b-9010-beba11f99f4e@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <71bf2956-3e29-45ad-a4e1-6a0540077a79@googlegroups.com> Subject: Re: Five Years After From: Robert Eachus Injection-Date: Thu, 25 Jan 2018 00:43:42 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:50127 Date: 2018-01-24T16:43:41-08:00 List-Id: On Wednesday, January 24, 2018 at 2:06:52 PM UTC-5, Simon Clubley wrote: > Oh, and about item (4). Apart from needing to call adainit/adafinal, > there's this little gem taken from: >=20 > https://gcc.gnu.org/onlinedocs/gnat_ugn/Binding-with-Non-Ada-Main-Program= s.html >=20 > |Currently the GNAT run time requires a FPU using 80 bits mode precision.= Under > |targets where this is not the default it is required to call > |GNAT.Float_Control.Reset before using floating point numbers (this inclu= de > |float computation, float input and output) in the Ada code. A side effec= t is > |that this could be the wrong mode for the foreign code where floating po= int > |computation could be broken after this call.=20 This may look horrible/ It is correct, but not very horrible. There are f= our use cases here: 1) You are on a PC with an x86, AMD64 (EM64_T), an IBM mainframe or several= other chips? On the PC there is 80-bit support (old x87 floating-point) b= ut you may prefer to use SIMD 64-bit floating point. On IBM Z-series, they= have a funky 128-bit type which may fit your needs. Anyway you are covere= d (just use Float for 32-bits or Long_Float for 64-bits. If the compiler w= ants to use 80-bit (IEEE Extended) for multiplication or division with two = fixed point operands, or fixed-point value output? Expect the (GNAT) compi= ler to handle those cases correctly. 2) You are on a chip which only supports up to 64-bit float types, and need= more. Years ago I wrote a package to do 64-bit float and integer arithmet= ic on machines which only supported up to 32 bit types. Hmmm. A 64-bit to = 128-bit float package should be possible, one sign bit, a 31-bit exponent a= nd a 97 bit mantissa including a hidden bit shouldn't be too hard. But thi= s should be a very small class. When high precision is needed even superco= mputers use polynomials in nth roots of one.* 3) You use 64-bit float and really care about the IEEE features like signed= zeroes, soft underflow, etc.* If the settings you care about are supporte= d, this is warning you that the code calling the Ada program may set the va= lues in a way you don't like. Worse, you need settings which are not suppo= rted by the chip. Tough! In theory, compilers should provide software to = emulate features that are not provided in hardware. For some settings, thi= s is easy. for some like rounding modes, very, very tough. You just have t= o ask yourself if you can live with the hardware. If you can't why are you= living with the hardware? 4) If you don't care about these issues, or more likely don't know enough a= bout them to care? Put in the GMAT.Float_Control_Reset call if the code wi= ll be running on a machine that needs it, and be aware that you could be li= ving in a state of sin. If both the calling code and the Ada code use floa= ting point types, and you expect to pass floating point parameters or data = back and forth? You are not only living in a state of sin, but may be gett= ing errors all over the place. (Worse, if you don't run and check test cas= es with known results, the code may run and produce bad answers!) In any c= ase you will need to learn enough about (IEEE) floating point types to make= sure that both halves of the program are using the same formats. What punishment goes with case 4? You may be forced to read Annex G. Wors= t case, read Annex G, IEEE 754-3008 and the GNAT documentation. Reading th= is might save a lot of pain: http://steve.hollasch.net/cgindex/coding/ieeef= loat.html As an example of the trouble you might get into, C specifies that certain f= loat functions actually take IEEE double values as parameters. If passed i= n registers, no real problems, but passing such values on the stack may be = lethal. I can tell you that such dragons exist but I don't even know the n= ames of all the languages where they can be hiding. (If all else fails, pa= ss the exponent and mantissa separately as integers. Used to have to do th= at to interface between DEC VAXes and other minicomputers.) * Decades ago, there was a special issue of Ada Letters which included the = full NUMWG report, including source, I think for test code which disassembl= ed floating-point numbers into exponent and mantissa. Is that source on-li= ne anywhere? I think it supports up to 128-bit float types, but the code i= s designed for accuracy and readability, not speed. =20